| | @@ -1162,11 +1162,11 @@ |
| 1162 | 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | 1164 | */ |
| 1165 | 1165 | #define SQLITE_VERSION "3.32.0" |
| 1166 | 1166 | #define SQLITE_VERSION_NUMBER 3032000 |
| 1167 | | -#define SQLITE_SOURCE_ID "2020-02-27 16:21:39 951b39ca74c9bd933139e099d5555283278db475f410f202c162e5d1e6aef933" |
| 1167 | +#define SQLITE_SOURCE_ID "2020-03-21 23:10:38 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84f525" |
| 1168 | 1168 | |
| 1169 | 1169 | /* |
| 1170 | 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | 1172 | ** |
| | @@ -16539,11 +16539,10 @@ |
| 16539 | 16539 | ** have been filled out. If the schema changes, these column names might |
| 16540 | 16540 | ** changes and so the view will need to be reset. |
| 16541 | 16541 | */ |
| 16542 | 16542 | #define DB_SchemaLoaded 0x0001 /* The schema has been loaded */ |
| 16543 | 16543 | #define DB_UnresetViews 0x0002 /* Some views have defined column names */ |
| 16544 | | -#define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */ |
| 16545 | 16544 | #define DB_ResetWanted 0x0008 /* Reset the schema when nSchemaLock==0 */ |
| 16546 | 16545 | |
| 16547 | 16546 | /* |
| 16548 | 16547 | ** The number of different kinds of things that can be limited |
| 16549 | 16548 | ** using the sqlite3_limit() interface. |
| | @@ -16697,11 +16696,11 @@ |
| 16697 | 16696 | ** Each database connection is an instance of the following structure. |
| 16698 | 16697 | */ |
| 16699 | 16698 | struct sqlite3 { |
| 16700 | 16699 | sqlite3_vfs *pVfs; /* OS Interface */ |
| 16701 | 16700 | struct Vdbe *pVdbe; /* List of active virtual machines */ |
| 16702 | | - CollSeq *pDfltColl; /* The default collating sequence (BINARY) */ |
| 16701 | + CollSeq *pDfltColl; /* BINARY collseq for the database encoding */ |
| 16703 | 16702 | sqlite3_mutex *mutex; /* Connection mutex */ |
| 16704 | 16703 | Db *aDb; /* All backends */ |
| 16705 | 16704 | int nDb; /* Number of backends currently in use */ |
| 16706 | 16705 | u32 mDbFlags; /* flags recording internal state */ |
| 16707 | 16706 | u64 flags; /* flags settable by pragmas. See below */ |
| | @@ -16906,10 +16905,11 @@ |
| 16906 | 16905 | #define DBFLAG_PreferBuiltin 0x0002 /* Preference to built-in funcs */ |
| 16907 | 16906 | #define DBFLAG_Vacuum 0x0004 /* Currently in a VACUUM */ |
| 16908 | 16907 | #define DBFLAG_VacuumInto 0x0008 /* Currently running VACUUM INTO */ |
| 16909 | 16908 | #define DBFLAG_SchemaKnownOk 0x0010 /* Schema is known to be valid */ |
| 16910 | 16909 | #define DBFLAG_InternalFunc 0x0020 /* Allow use of internal functions */ |
| 16910 | +#define DBFLAG_EncodingFixed 0x0040 /* No longer possible to change enc. */ |
| 16911 | 16911 | |
| 16912 | 16912 | /* |
| 16913 | 16913 | ** Bits of the sqlite3.dbOptFlags field that are used by the |
| 16914 | 16914 | ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to |
| 16915 | 16915 | ** selectively disable various optimizations. |
| | @@ -17869,10 +17869,13 @@ |
| 17869 | 17869 | char affExpr; /* affinity, or RAISE type */ |
| 17870 | 17870 | u8 op2; /* TK_REGISTER/TK_TRUTH: original value of Expr.op |
| 17871 | 17871 | ** TK_COLUMN: the value of p5 for OP_Column |
| 17872 | 17872 | ** TK_AGG_FUNCTION: nesting depth |
| 17873 | 17873 | ** TK_FUNCTION: NC_SelfRef flag if needs OP_PureFunc */ |
| 17874 | +#ifdef SQLITE_DEBUG |
| 17875 | + u8 vvaFlags; /* Verification flags. */ |
| 17876 | +#endif |
| 17874 | 17877 | u32 flags; /* Various flags. EP_* See below */ |
| 17875 | 17878 | union { |
| 17876 | 17879 | char *zToken; /* Token value. Zero terminated and dequoted */ |
| 17877 | 17880 | int iValue; /* Non-negative integer value if EP_IntValue */ |
| 17878 | 17881 | } u; |
| | @@ -17943,11 +17946,11 @@ |
| 17943 | 17946 | #define EP_Skip 0x001000 /* Operator does not contribute to affinity */ |
| 17944 | 17947 | #define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */ |
| 17945 | 17948 | #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */ |
| 17946 | 17949 | #define EP_Win 0x008000 /* Contains window functions */ |
| 17947 | 17950 | #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */ |
| 17948 | | -#define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */ |
| 17951 | + /* 0x020000 // available for reuse */ |
| 17949 | 17952 | #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */ |
| 17950 | 17953 | #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */ |
| 17951 | 17954 | #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */ |
| 17952 | 17955 | #define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */ |
| 17953 | 17956 | #define EP_Alias 0x400000 /* Is an alias for a result set column */ |
| | @@ -17957,10 +17960,11 @@ |
| 17957 | 17960 | #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */ |
| 17958 | 17961 | #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */ |
| 17959 | 17962 | #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */ |
| 17960 | 17963 | #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */ |
| 17961 | 17964 | #define EP_FromDDL 0x40000000 /* Originates from sqlite_master */ |
| 17965 | + /* 0x80000000 // Available */ |
| 17962 | 17966 | |
| 17963 | 17967 | /* |
| 17964 | 17968 | ** The EP_Propagate mask is a set of properties that automatically propagate |
| 17965 | 17969 | ** upwards into parent nodes. |
| 17966 | 17970 | */ |
| | @@ -17975,18 +17979,28 @@ |
| 17975 | 17979 | #define ExprSetProperty(E,P) (E)->flags|=(P) |
| 17976 | 17980 | #define ExprClearProperty(E,P) (E)->flags&=~(P) |
| 17977 | 17981 | #define ExprAlwaysTrue(E) (((E)->flags&(EP_FromJoin|EP_IsTrue))==EP_IsTrue) |
| 17978 | 17982 | #define ExprAlwaysFalse(E) (((E)->flags&(EP_FromJoin|EP_IsFalse))==EP_IsFalse) |
| 17979 | 17983 | |
| 17984 | + |
| 17985 | +/* Flags for use with Expr.vvaFlags |
| 17986 | +*/ |
| 17987 | +#define EP_NoReduce 0x01 /* Cannot EXPRDUP_REDUCE this Expr */ |
| 17988 | +#define EP_Immutable 0x02 /* Do not change this Expr node */ |
| 17989 | + |
| 17980 | 17990 | /* The ExprSetVVAProperty() macro is used for Verification, Validation, |
| 17981 | 17991 | ** and Accreditation only. It works like ExprSetProperty() during VVA |
| 17982 | 17992 | ** processes but is a no-op for delivery. |
| 17983 | 17993 | */ |
| 17984 | 17994 | #ifdef SQLITE_DEBUG |
| 17985 | | -# define ExprSetVVAProperty(E,P) (E)->flags|=(P) |
| 17995 | +# define ExprSetVVAProperty(E,P) (E)->vvaFlags|=(P) |
| 17996 | +# define ExprHasVVAProperty(E,P) (((E)->vvaFlags&(P))!=0) |
| 17997 | +# define ExprClearVVAProperties(E) (E)->vvaFlags = 0 |
| 17986 | 17998 | #else |
| 17987 | 17999 | # define ExprSetVVAProperty(E,P) |
| 18000 | +# define ExprHasVVAProperty(E,P) 0 |
| 18001 | +# define ExprClearVVAProperties(E) |
| 17988 | 18002 | #endif |
| 17989 | 18003 | |
| 17990 | 18004 | /* |
| 17991 | 18005 | ** Macros to determine the number of bytes required by a normal Expr |
| 17992 | 18006 | ** struct, an Expr struct with the EP_Reduced flag set in Expr.flags |
| | @@ -18956,10 +18970,11 @@ |
| 18956 | 18970 | Select *pSelect; /* HAVING to WHERE clause ctx */ |
| 18957 | 18971 | struct WindowRewrite *pRewrite; /* Window rewrite context */ |
| 18958 | 18972 | struct WhereConst *pConst; /* WHERE clause constants */ |
| 18959 | 18973 | struct RenameCtx *pRename; /* RENAME COLUMN context */ |
| 18960 | 18974 | struct Table *pTab; /* Table of generated column */ |
| 18975 | + struct SrcList_item *pSrcItem; /* A single FROM clause item */ |
| 18961 | 18976 | } u; |
| 18962 | 18977 | }; |
| 18963 | 18978 | |
| 18964 | 18979 | /* Forward declarations */ |
| 18965 | 18980 | SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*); |
| | @@ -19500,11 +19515,11 @@ |
| 19500 | 19515 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 19501 | 19516 | SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(Parse*, Column*, int); |
| 19502 | 19517 | #endif |
| 19503 | 19518 | SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int); |
| 19504 | 19519 | SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int); |
| 19505 | | -SQLITE_PRIVATE int sqlite3ExprCodeAtInit(Parse*, Expr*, int); |
| 19520 | +SQLITE_PRIVATE int sqlite3ExprCodeRunJustOnce(Parse*, Expr*, int); |
| 19506 | 19521 | SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*); |
| 19507 | 19522 | SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int); |
| 19508 | 19523 | SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8); |
| 19509 | 19524 | #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */ |
| 19510 | 19525 | #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */ |
| | @@ -19655,10 +19670,11 @@ |
| 19655 | 19670 | # define sqlite3AuthRead(a,b,c,d) |
| 19656 | 19671 | # define sqlite3AuthCheck(a,b,c,d,e) SQLITE_OK |
| 19657 | 19672 | # define sqlite3AuthContextPush(a,b,c) |
| 19658 | 19673 | # define sqlite3AuthContextPop(a) ((void)(a)) |
| 19659 | 19674 | #endif |
| 19675 | +SQLITE_PRIVATE int sqlite3DbIsNamed(sqlite3 *db, int iDb, const char *zName); |
| 19660 | 19676 | SQLITE_PRIVATE void sqlite3Attach(Parse*, Expr*, Expr*, Expr*); |
| 19661 | 19677 | SQLITE_PRIVATE void sqlite3Detach(Parse*, Expr*); |
| 19662 | 19678 | SQLITE_PRIVATE void sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*); |
| 19663 | 19679 | SQLITE_PRIVATE int sqlite3FixSrcList(DbFixer*, SrcList*); |
| 19664 | 19680 | SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*); |
| | @@ -19714,14 +19730,14 @@ |
| 19714 | 19730 | #define putVarint sqlite3PutVarint |
| 19715 | 19731 | |
| 19716 | 19732 | |
| 19717 | 19733 | SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3*, Index*); |
| 19718 | 19734 | SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int); |
| 19719 | | -SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2); |
| 19720 | | -SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); |
| 19735 | +SQLITE_PRIVATE char sqlite3CompareAffinity(const Expr *pExpr, char aff2); |
| 19736 | +SQLITE_PRIVATE int sqlite3IndexAffinityOk(const Expr *pExpr, char idx_affinity); |
| 19721 | 19737 | SQLITE_PRIVATE char sqlite3TableColumnAffinity(Table*,int); |
| 19722 | | -SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr); |
| 19738 | +SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr); |
| 19723 | 19739 | SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8); |
| 19724 | 19740 | SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char*, i64*); |
| 19725 | 19741 | SQLITE_PRIVATE void sqlite3ErrorWithMsg(sqlite3*, int, const char*,...); |
| 19726 | 19742 | SQLITE_PRIVATE void sqlite3Error(sqlite3*,int); |
| 19727 | 19743 | SQLITE_PRIVATE void sqlite3SystemError(sqlite3*,int); |
| | @@ -19740,13 +19756,14 @@ |
| 19740 | 19756 | SQLITE_PRIVATE const char *sqlite3ErrStr(int); |
| 19741 | 19757 | SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); |
| 19742 | 19758 | SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); |
| 19743 | 19759 | SQLITE_PRIVATE int sqlite3IsBinary(const CollSeq*); |
| 19744 | 19760 | SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); |
| 19745 | | -SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr); |
| 19746 | | -SQLITE_PRIVATE CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, Expr *pExpr); |
| 19747 | | -SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse*,Expr*,Expr*); |
| 19761 | +SQLITE_PRIVATE void sqlite3SetTextEncoding(sqlite3 *db, u8); |
| 19762 | +SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr); |
| 19763 | +SQLITE_PRIVATE CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, const Expr *pExpr); |
| 19764 | +SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse*,const Expr*,const Expr*); |
| 19748 | 19765 | SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*, int); |
| 19749 | 19766 | SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*); |
| 19750 | 19767 | SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr*); |
| 19751 | 19768 | SQLITE_PRIVATE Expr *sqlite3ExprSkipCollateAndLikely(Expr*); |
| 19752 | 19769 | SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *); |
| | @@ -19809,10 +19826,11 @@ |
| 19809 | 19826 | const struct ExprList_item*, |
| 19810 | 19827 | const char*, |
| 19811 | 19828 | const char*, |
| 19812 | 19829 | const char* |
| 19813 | 19830 | ); |
| 19831 | +SQLITE_PRIVATE Bitmask sqlite3ExprColUsed(Expr*); |
| 19814 | 19832 | SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*); |
| 19815 | 19833 | SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*); |
| 19816 | 19834 | SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*); |
| 19817 | 19835 | SQLITE_PRIVATE int sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*); |
| 19818 | 19836 | SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*); |
| | @@ -19973,12 +19991,12 @@ |
| 19973 | 19991 | #ifdef SQLITE_ENABLE_NORMALIZE |
| 19974 | 19992 | SQLITE_PRIVATE char *sqlite3Normalize(Vdbe*, const char*); |
| 19975 | 19993 | #endif |
| 19976 | 19994 | SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*); |
| 19977 | 19995 | SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*); |
| 19978 | | -SQLITE_PRIVATE CollSeq *sqlite3ExprCompareCollSeq(Parse*,Expr*); |
| 19979 | | -SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *); |
| 19996 | +SQLITE_PRIVATE CollSeq *sqlite3ExprCompareCollSeq(Parse*,const Expr*); |
| 19997 | +SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, const Expr*, const Expr*); |
| 19980 | 19998 | SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3*); |
| 19981 | 19999 | SQLITE_PRIVATE const char *sqlite3JournalModename(int); |
| 19982 | 20000 | #ifndef SQLITE_OMIT_WAL |
| 19983 | 20001 | SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3*, int, int, int*, int*); |
| 19984 | 20002 | SQLITE_PRIVATE int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int); |
| | @@ -20947,13 +20965,13 @@ |
| 20947 | 20965 | #endif |
| 20948 | 20966 | u16 nResColumn; /* Number of columns in one row of the result set */ |
| 20949 | 20967 | u8 errorAction; /* Recovery action to do in case of an error */ |
| 20950 | 20968 | u8 minWriteFileFormat; /* Minimum file format for writable database files */ |
| 20951 | 20969 | u8 prepFlags; /* SQLITE_PREPARE_* flags */ |
| 20970 | + u8 doingRerun; /* True if rerunning after an auto-reprepare */ |
| 20952 | 20971 | bft expired:2; /* 1: recompile VM immediately 2: when convenient */ |
| 20953 | 20972 | bft explain:2; /* True if EXPLAIN present on SQL command */ |
| 20954 | | - bft doingRerun:1; /* True if rerunning after an auto-reprepare */ |
| 20955 | 20973 | bft changeCntOn:1; /* True to update the change-counter */ |
| 20956 | 20974 | bft runOnlyOnce:1; /* Automatically expire on reset */ |
| 20957 | 20975 | bft usesStmtJournal:1; /* True if uses a statement journal */ |
| 20958 | 20976 | bft readOnly:1; /* True for statements that do not write */ |
| 20959 | 20977 | bft bIsReader:1; /* True for statements that read */ |
| | @@ -29390,12 +29408,12 @@ |
| 29390 | 29408 | sqlite3_str_appendf(&x, " %s.%s", pItem->zDatabase, pItem->zName); |
| 29391 | 29409 | }else if( pItem->zName ){ |
| 29392 | 29410 | sqlite3_str_appendf(&x, " %s", pItem->zName); |
| 29393 | 29411 | } |
| 29394 | 29412 | if( pItem->pTab ){ |
| 29395 | | - sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p", |
| 29396 | | - pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab); |
| 29413 | + sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx", |
| 29414 | + pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed); |
| 29397 | 29415 | } |
| 29398 | 29416 | if( pItem->zAlias ){ |
| 29399 | 29417 | sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias); |
| 29400 | 29418 | } |
| 29401 | 29419 | if( pItem->fg.jointype & JT_LEFT ){ |
| | @@ -29650,27 +29668,30 @@ |
| 29650 | 29668 | ** Generate a human-readable explanation of an expression tree. |
| 29651 | 29669 | */ |
| 29652 | 29670 | SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){ |
| 29653 | 29671 | const char *zBinOp = 0; /* Binary operator */ |
| 29654 | 29672 | const char *zUniOp = 0; /* Unary operator */ |
| 29655 | | - char zFlgs[60]; |
| 29673 | + char zFlgs[200]; |
| 29656 | 29674 | pView = sqlite3TreeViewPush(pView, moreToFollow); |
| 29657 | 29675 | if( pExpr==0 ){ |
| 29658 | 29676 | sqlite3TreeViewLine(pView, "nil"); |
| 29659 | 29677 | sqlite3TreeViewPop(pView); |
| 29660 | 29678 | return; |
| 29661 | 29679 | } |
| 29662 | | - if( pExpr->flags || pExpr->affExpr ){ |
| 29680 | + if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags ){ |
| 29663 | 29681 | StrAccum x; |
| 29664 | 29682 | sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0); |
| 29665 | 29683 | sqlite3_str_appendf(&x, " fg.af=%x.%c", |
| 29666 | 29684 | pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n'); |
| 29667 | 29685 | if( ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 29668 | 29686 | sqlite3_str_appendf(&x, " iRJT=%d", pExpr->iRightJoinTable); |
| 29669 | 29687 | } |
| 29670 | 29688 | if( ExprHasProperty(pExpr, EP_FromDDL) ){ |
| 29671 | 29689 | sqlite3_str_appendf(&x, " DDL"); |
| 29690 | + } |
| 29691 | + if( ExprHasVVAProperty(pExpr, EP_Immutable) ){ |
| 29692 | + sqlite3_str_appendf(&x, " IMMUTABLE"); |
| 29672 | 29693 | } |
| 29673 | 29694 | sqlite3StrAccumFinish(&x); |
| 29674 | 29695 | }else{ |
| 29675 | 29696 | zFlgs[0] = 0; |
| 29676 | 29697 | } |
| | @@ -29774,10 +29795,11 @@ |
| 29774 | 29795 | case TK_SLASH: zBinOp = "DIV"; break; |
| 29775 | 29796 | case TK_LSHIFT: zBinOp = "LSHIFT"; break; |
| 29776 | 29797 | case TK_RSHIFT: zBinOp = "RSHIFT"; break; |
| 29777 | 29798 | case TK_CONCAT: zBinOp = "CONCAT"; break; |
| 29778 | 29799 | case TK_DOT: zBinOp = "DOT"; break; |
| 29800 | + case TK_LIMIT: zBinOp = "LIMIT"; break; |
| 29779 | 29801 | |
| 29780 | 29802 | case TK_UMINUS: zUniOp = "UMINUS"; break; |
| 29781 | 29803 | case TK_UPLUS: zUniOp = "UPLUS"; break; |
| 29782 | 29804 | case TK_BITNOT: zUniOp = "BITNOT"; break; |
| 29783 | 29805 | case TK_NOT: zUniOp = "NOT"; break; |
| | @@ -50895,11 +50917,11 @@ |
| 50895 | 50917 | } |
| 50896 | 50918 | |
| 50897 | 50919 | /* |
| 50898 | 50920 | ** Allocate a new RowSetEntry object that is associated with the |
| 50899 | 50921 | ** given RowSet. Return a pointer to the new and completely uninitialized |
| 50900 | | -** objected. |
| 50922 | +** object. |
| 50901 | 50923 | ** |
| 50902 | 50924 | ** In an OOM situation, the RowSet.db->mallocFailed flag is set and this |
| 50903 | 50925 | ** routine returns NULL. |
| 50904 | 50926 | */ |
| 50905 | 50927 | static struct RowSetEntry *rowSetEntryAlloc(RowSet *p){ |
| | @@ -51171,11 +51193,11 @@ |
| 51171 | 51193 | if( iBatch!=pRowSet->iBatch ){ /*OPTIMIZATION-IF-FALSE*/ |
| 51172 | 51194 | p = pRowSet->pEntry; |
| 51173 | 51195 | if( p ){ |
| 51174 | 51196 | struct RowSetEntry **ppPrevTree = &pRowSet->pForest; |
| 51175 | 51197 | if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/ |
| 51176 | | - /* Only sort the current set of entiries if they need it */ |
| 51198 | + /* Only sort the current set of entries if they need it */ |
| 51177 | 51199 | p = rowSetEntrySort(p); |
| 51178 | 51200 | } |
| 51179 | 51201 | for(pTree = pRowSet->pForest; pTree; pTree=pTree->pRight){ |
| 51180 | 51202 | ppPrevTree = &pTree->pRight; |
| 51181 | 51203 | if( pTree->pLeft==0 ){ |
| | @@ -64536,11 +64558,11 @@ |
| 64536 | 64558 | ** free-list for reuse. It returns false if it is safe to retrieve the |
| 64537 | 64559 | ** page from the pager layer with the 'no-content' flag set. True otherwise. |
| 64538 | 64560 | */ |
| 64539 | 64561 | static int btreeGetHasContent(BtShared *pBt, Pgno pgno){ |
| 64540 | 64562 | Bitvec *p = pBt->pHasContent; |
| 64541 | | - return (p && (pgno>sqlite3BitvecSize(p) || sqlite3BitvecTest(p, pgno))); |
| 64563 | + return p && (pgno>sqlite3BitvecSize(p) || sqlite3BitvecTestNotNull(p, pgno)); |
| 64542 | 64564 | } |
| 64543 | 64565 | |
| 64544 | 64566 | /* |
| 64545 | 64567 | ** Clear (destroy) the BtShared.pHasContent bitvec. This should be |
| 64546 | 64568 | ** invoked at the conclusion of each write-transaction. |
| | @@ -76180,23 +76202,18 @@ |
| 76180 | 76202 | u16 mFlags; |
| 76181 | 76203 | if( pVdbe->db->flags & SQLITE_VdbeTrace ){ |
| 76182 | 76204 | sqlite3DebugPrintf("Invalidate R[%d] due to change in R[%d]\n", |
| 76183 | 76205 | (int)(pX - pVdbe->aMem), (int)(pMem - pVdbe->aMem)); |
| 76184 | 76206 | } |
| 76185 | | - /* If pX is marked as a shallow copy of pMem, then verify that |
| 76207 | + /* If pX is marked as a shallow copy of pMem, then try to verify that |
| 76186 | 76208 | ** no significant changes have been made to pX since the OP_SCopy. |
| 76187 | 76209 | ** A significant change would indicated a missed call to this |
| 76188 | 76210 | ** function for pX. Minor changes, such as adding or removing a |
| 76189 | 76211 | ** dual type, are allowed, as long as the underlying value is the |
| 76190 | 76212 | ** same. */ |
| 76191 | 76213 | mFlags = pMem->flags & pX->flags & pX->mScopyFlags; |
| 76192 | 76214 | assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i ); |
| 76193 | | - /* assert( (mFlags&MEM_Real)==0 || pMem->u.r==pX->u.r ); */ |
| 76194 | | - /* ^^ */ |
| 76195 | | - /* Cannot reliably compare doubles for equality */ |
| 76196 | | - assert( (mFlags&MEM_Str)==0 || (pMem->n==pX->n && pMem->z==pX->z) ); |
| 76197 | | - assert( (mFlags&MEM_Blob)==0 || sqlite3BlobCompare(pMem,pX)==0 ); |
| 76198 | 76215 | |
| 76199 | 76216 | /* pMem is the register that is changing. But also mark pX as |
| 76200 | 76217 | ** undefined so that we can quickly detect the shallow-copy error */ |
| 76201 | 76218 | pX->flags = MEM_Undefined; |
| 76202 | 76219 | pX->pScopyFrom = 0; |
| | @@ -77547,11 +77564,11 @@ |
| 77547 | 77564 | (void)z2; |
| 77548 | 77565 | } |
| 77549 | 77566 | #endif |
| 77550 | 77567 | |
| 77551 | 77568 | /* |
| 77552 | | -** Add a new OP_ opcode. |
| 77569 | +** Add a new OP_Explain opcode. |
| 77553 | 77570 | ** |
| 77554 | 77571 | ** If the bPush flag is true, then make this opcode the parent for |
| 77555 | 77572 | ** subsequent Explains until sqlite3VdbeExplainPop() is called. |
| 77556 | 77573 | */ |
| 77557 | 77574 | SQLITE_PRIVATE void sqlite3VdbeExplain(Parse *pParse, u8 bPush, const char *zFmt, ...){ |
| | @@ -78781,12 +78798,15 @@ |
| 78781 | 78798 | displayP4Expr(&x, pOp->p4.pExpr); |
| 78782 | 78799 | break; |
| 78783 | 78800 | } |
| 78784 | 78801 | #endif |
| 78785 | 78802 | case P4_COLLSEQ: { |
| 78803 | + static const char *const encnames[] = {"?", "8", "16LE", "16BE"}; |
| 78786 | 78804 | CollSeq *pColl = pOp->p4.pColl; |
| 78787 | | - sqlite3_str_appendf(&x, "(%.20s)", pColl->zName); |
| 78805 | + assert( pColl->enc>=0 && pColl->enc<4 ); |
| 78806 | + sqlite3_str_appendf(&x, "%.18s-%s", pColl->zName, |
| 78807 | + encnames[pColl->enc]); |
| 78788 | 78808 | break; |
| 78789 | 78809 | } |
| 78790 | 78810 | case P4_FUNCDEF: { |
| 78791 | 78811 | FuncDef *pDef = pOp->p4.pFunc; |
| 78792 | 78812 | sqlite3_str_appendf(&x, "%s(%d)", pDef->zName, pDef->nArg); |
| | @@ -79495,10 +79515,11 @@ |
| 79495 | 79515 | "addr", "opcode", "p1", "p2", "p3", "p4", "p5", "comment", |
| 79496 | 79516 | "id", "parent", "notused", "detail" |
| 79497 | 79517 | }; |
| 79498 | 79518 | int iFirst, mx, i; |
| 79499 | 79519 | if( nMem<10 ) nMem = 10; |
| 79520 | + p->explain = pParse->explain; |
| 79500 | 79521 | if( pParse->explain==2 ){ |
| 79501 | 79522 | sqlite3VdbeSetNumCols(p, 4); |
| 79502 | 79523 | iFirst = 8; |
| 79503 | 79524 | mx = 12; |
| 79504 | 79525 | }else{ |
| | @@ -79545,11 +79566,10 @@ |
| 79545 | 79566 | } |
| 79546 | 79567 | } |
| 79547 | 79568 | |
| 79548 | 79569 | p->pVList = pParse->pVList; |
| 79549 | 79570 | pParse->pVList = 0; |
| 79550 | | - p->explain = pParse->explain; |
| 79551 | 79571 | if( db->mallocFailed ){ |
| 79552 | 79572 | p->nVar = 0; |
| 79553 | 79573 | p->nCursor = 0; |
| 79554 | 79574 | p->nMem = 0; |
| 79555 | 79575 | }else{ |
| | @@ -86230,11 +86250,10 @@ |
| 86230 | 86250 | u16 flags2; /* Initial flags for P2 */ |
| 86231 | 86251 | |
| 86232 | 86252 | pIn1 = &aMem[pOp->p1]; |
| 86233 | 86253 | pIn2 = &aMem[pOp->p2]; |
| 86234 | 86254 | pOut = &aMem[pOp->p3]; |
| 86235 | | - testcase( pIn1==pIn2 ); |
| 86236 | 86255 | testcase( pOut==pIn2 ); |
| 86237 | 86256 | assert( pIn1!=pOut ); |
| 86238 | 86257 | flags1 = pIn1->flags; |
| 86239 | 86258 | testcase( flags1 & MEM_Null ); |
| 86240 | 86259 | testcase( pIn2->flags & MEM_Null ); |
| | @@ -88351,11 +88370,11 @@ |
| 88351 | 88370 | ** |
| 88352 | 88371 | ** Allowed P5 bits: |
| 88353 | 88372 | ** <ul> |
| 88354 | 88373 | ** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for |
| 88355 | 88374 | ** equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT |
| 88356 | | -** of OP_SeekLE/OP_IdxGT) |
| 88375 | +** of OP_SeekLE/OP_IdxLT) |
| 88357 | 88376 | ** </ul> |
| 88358 | 88377 | ** |
| 88359 | 88378 | ** The P4 value may be either an integer (P4_INT32) or a pointer to |
| 88360 | 88379 | ** a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo |
| 88361 | 88380 | ** object, then table being opened must be an [index b-tree] where the |
| | @@ -88381,11 +88400,11 @@ |
| 88381 | 88400 | ** |
| 88382 | 88401 | ** Allowed P5 bits: |
| 88383 | 88402 | ** <ul> |
| 88384 | 88403 | ** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for |
| 88385 | 88404 | ** equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT |
| 88386 | | -** of OP_SeekLE/OP_IdxGT) |
| 88405 | +** of OP_SeekLE/OP_IdxLT) |
| 88387 | 88406 | ** </ul> |
| 88388 | 88407 | ** |
| 88389 | 88408 | ** See also: OP_OpenRead, OP_OpenWrite |
| 88390 | 88409 | */ |
| 88391 | 88410 | /* Opcode: OpenWrite P1 P2 P3 P4 P5 |
| | @@ -88405,11 +88424,11 @@ |
| 88405 | 88424 | ** |
| 88406 | 88425 | ** Allowed P5 bits: |
| 88407 | 88426 | ** <ul> |
| 88408 | 88427 | ** <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for |
| 88409 | 88428 | ** equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT |
| 88410 | | -** of OP_SeekLE/OP_IdxGT) |
| 88429 | +** of OP_SeekLE/OP_IdxLT) |
| 88411 | 88430 | ** <li> <b>0x08 OPFLAG_FORDELETE</b>: This cursor is used only to seek |
| 88412 | 88431 | ** and subsequently delete entries in an index btree. This is a |
| 88413 | 88432 | ** hint to the storage engine that the storage engine is allowed to |
| 88414 | 88433 | ** ignore. The hint is not used by the official SQLite b*tree storage |
| 88415 | 88434 | ** engine, but is used by COMDB2. |
| | @@ -88517,13 +88536,11 @@ |
| 88517 | 88536 | |
| 88518 | 88537 | open_cursor_set_hints: |
| 88519 | 88538 | assert( OPFLAG_BULKCSR==BTREE_BULKLOAD ); |
| 88520 | 88539 | assert( OPFLAG_SEEKEQ==BTREE_SEEK_EQ ); |
| 88521 | 88540 | testcase( pOp->p5 & OPFLAG_BULKCSR ); |
| 88522 | | -#ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 88523 | 88541 | testcase( pOp->p2 & OPFLAG_SEEKEQ ); |
| 88524 | | -#endif |
| 88525 | 88542 | sqlite3BtreeCursorHintFlags(pCur->uc.pCursor, |
| 88526 | 88543 | (pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ))); |
| 88527 | 88544 | if( rc ) goto abort_due_to_error; |
| 88528 | 88545 | break; |
| 88529 | 88546 | } |
| | @@ -88775,15 +88792,17 @@ |
| 88775 | 88792 | ** Reposition cursor P1 so that it points to the smallest entry that |
| 88776 | 88793 | ** is greater than or equal to the key value. If there are no records |
| 88777 | 88794 | ** greater than or equal to the key and P2 is not zero, then jump to P2. |
| 88778 | 88795 | ** |
| 88779 | 88796 | ** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this |
| 88780 | | -** opcode will always land on a record that equally equals the key, or |
| 88781 | | -** else jump immediately to P2. When the cursor is OPFLAG_SEEKEQ, this |
| 88782 | | -** opcode must be followed by an IdxLE opcode with the same arguments. |
| 88783 | | -** The IdxLE opcode will be skipped if this opcode succeeds, but the |
| 88784 | | -** IdxLE opcode will be used on subsequent loop iterations. |
| 88797 | +** opcode will either land on a record that exactly matches the key, or |
| 88798 | +** else it will cause a jump to P2. When the cursor is OPFLAG_SEEKEQ, |
| 88799 | +** this opcode must be followed by an IdxLE opcode with the same arguments. |
| 88800 | +** The IdxGT opcode will be skipped if this opcode succeeds, but the |
| 88801 | +** IdxGT opcode will be used on subsequent loop iterations. The |
| 88802 | +** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this |
| 88803 | +** is an equality search. |
| 88785 | 88804 | ** |
| 88786 | 88805 | ** This opcode leaves the cursor configured to move in forward order, |
| 88787 | 88806 | ** from the beginning toward the end. In other words, the cursor is |
| 88788 | 88807 | ** configured to use Next, not Prev. |
| 88789 | 88808 | ** |
| | @@ -88795,11 +88814,11 @@ |
| 88795 | 88814 | ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys), |
| 88796 | 88815 | ** use the value in register P3 as a key. If cursor P1 refers |
| 88797 | 88816 | ** to an SQL index, then P3 is the first in an array of P4 registers |
| 88798 | 88817 | ** that are used as an unpacked index key. |
| 88799 | 88818 | ** |
| 88800 | | -** Reposition cursor P1 so that it points to the smallest entry that |
| 88819 | +** Reposition cursor P1 so that it points to the smallest entry that |
| 88801 | 88820 | ** is greater than the key value. If there are no records greater than |
| 88802 | 88821 | ** the key and P2 is not zero, then jump to P2. |
| 88803 | 88822 | ** |
| 88804 | 88823 | ** This opcode leaves the cursor configured to move in forward order, |
| 88805 | 88824 | ** from the beginning toward the end. In other words, the cursor is |
| | @@ -88840,15 +88859,17 @@ |
| 88840 | 88859 | ** This opcode leaves the cursor configured to move in reverse order, |
| 88841 | 88860 | ** from the end toward the beginning. In other words, the cursor is |
| 88842 | 88861 | ** configured to use Prev, not Next. |
| 88843 | 88862 | ** |
| 88844 | 88863 | ** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this |
| 88845 | | -** opcode will always land on a record that equally equals the key, or |
| 88846 | | -** else jump immediately to P2. When the cursor is OPFLAG_SEEKEQ, this |
| 88847 | | -** opcode must be followed by an IdxGE opcode with the same arguments. |
| 88864 | +** opcode will either land on a record that exactly matches the key, or |
| 88865 | +** else it will cause a jump to P2. When the cursor is OPFLAG_SEEKEQ, |
| 88866 | +** this opcode must be followed by an IdxLE opcode with the same arguments. |
| 88848 | 88867 | ** The IdxGE opcode will be skipped if this opcode succeeds, but the |
| 88849 | | -** IdxGE opcode will be used on subsequent loop iterations. |
| 88868 | +** IdxGE opcode will be used on subsequent loop iterations. The |
| 88869 | +** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this |
| 88870 | +** is an equality search. |
| 88850 | 88871 | ** |
| 88851 | 88872 | ** See also: Found, NotFound, SeekGt, SeekGe, SeekLt |
| 88852 | 88873 | */ |
| 88853 | 88874 | case OP_SeekLT: /* jump, in3, group */ |
| 88854 | 88875 | case OP_SeekLE: /* jump, in3, group */ |
| | @@ -88881,11 +88902,11 @@ |
| 88881 | 88902 | |
| 88882 | 88903 | pC->deferredMoveto = 0; |
| 88883 | 88904 | pC->cacheStatus = CACHE_STALE; |
| 88884 | 88905 | if( pC->isTable ){ |
| 88885 | 88906 | u16 flags3, newType; |
| 88886 | | - /* The BTREE_SEEK_EQ flag is only set on index cursors */ |
| 88907 | + /* The OPFLAG_SEEKEQ/BTREE_SEEK_EQ flag is only set on index cursors */ |
| 88887 | 88908 | assert( sqlite3BtreeCursorHasHint(pC->uc.pCursor, BTREE_SEEK_EQ)==0 |
| 88888 | 88909 | || CORRUPT_DB ); |
| 88889 | 88910 | |
| 88890 | 88911 | /* The input value in P3 might be of any type: integer, real, string, |
| 88891 | 88912 | ** blob, or NULL. But it needs to be an integer before we can do |
| | @@ -88940,18 +88961,21 @@ |
| 88940 | 88961 | pC->movetoTarget = iKey; /* Used by OP_Delete */ |
| 88941 | 88962 | if( rc!=SQLITE_OK ){ |
| 88942 | 88963 | goto abort_due_to_error; |
| 88943 | 88964 | } |
| 88944 | 88965 | }else{ |
| 88945 | | - /* For a cursor with the BTREE_SEEK_EQ hint, only the OP_SeekGE and |
| 88946 | | - ** OP_SeekLE opcodes are allowed, and these must be immediately followed |
| 88947 | | - ** by an OP_IdxGT or OP_IdxLT opcode, respectively, with the same key. |
| 88966 | + /* For a cursor with the OPFLAG_SEEKEQ/BTREE_SEEK_EQ hint, only the |
| 88967 | + ** OP_SeekGE and OP_SeekLE opcodes are allowed, and these must be |
| 88968 | + ** immediately followed by an OP_IdxGT or OP_IdxLT opcode, respectively, |
| 88969 | + ** with the same key. |
| 88948 | 88970 | */ |
| 88949 | 88971 | if( sqlite3BtreeCursorHasHint(pC->uc.pCursor, BTREE_SEEK_EQ) ){ |
| 88950 | 88972 | eqOnly = 1; |
| 88951 | 88973 | assert( pOp->opcode==OP_SeekGE || pOp->opcode==OP_SeekLE ); |
| 88952 | 88974 | assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT ); |
| 88975 | + assert( pOp->opcode==OP_SeekGE || pOp[1].opcode==OP_IdxLT ); |
| 88976 | + assert( pOp->opcode==OP_SeekLE || pOp[1].opcode==OP_IdxGT ); |
| 88953 | 88977 | assert( pOp[1].p1==pOp[0].p1 ); |
| 88954 | 88978 | assert( pOp[1].p2==pOp[0].p2 ); |
| 88955 | 88979 | assert( pOp[1].p3==pOp[0].p3 ); |
| 88956 | 88980 | assert( pOp[1].p4.i==pOp[0].p4.i ); |
| 88957 | 88981 | } |
| | @@ -91162,11 +91186,11 @@ |
| 91162 | 91186 | ** try to reuse register values from the first use. */ |
| 91163 | 91187 | { |
| 91164 | 91188 | int i; |
| 91165 | 91189 | for(i=0; i<p->nMem; i++){ |
| 91166 | 91190 | aMem[i].pScopyFrom = 0; /* Prevent false-positive AboutToChange() errs */ |
| 91167 | | - aMem[i].flags |= MEM_Undefined; /* Cause a fault if this reg is reused */ |
| 91191 | + MemSetTypeFlag(&aMem[i], MEM_Undefined); /* Fault if this reg is reused */ |
| 91168 | 91192 | } |
| 91169 | 91193 | } |
| 91170 | 91194 | #endif |
| 91171 | 91195 | pOp = &aOp[-1]; |
| 91172 | 91196 | goto check_for_interrupt; |
| | @@ -96555,19 +96579,20 @@ |
| 96555 | 96579 | SrcList *pSrc; |
| 96556 | 96580 | int i; |
| 96557 | 96581 | struct SrcList_item *pItem; |
| 96558 | 96582 | |
| 96559 | 96583 | pSrc = p->pSrc; |
| 96560 | | - assert( pSrc!=0 ); |
| 96561 | | - for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){ |
| 96562 | | - if( pItem->pSelect && sqlite3WalkSelect(pWalker, pItem->pSelect) ){ |
| 96563 | | - return WRC_Abort; |
| 96564 | | - } |
| 96565 | | - if( pItem->fg.isTabFunc |
| 96566 | | - && sqlite3WalkExprList(pWalker, pItem->u1.pFuncArg) |
| 96567 | | - ){ |
| 96568 | | - return WRC_Abort; |
| 96584 | + if( pSrc ){ |
| 96585 | + for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){ |
| 96586 | + if( pItem->pSelect && sqlite3WalkSelect(pWalker, pItem->pSelect) ){ |
| 96587 | + return WRC_Abort; |
| 96588 | + } |
| 96589 | + if( pItem->fg.isTabFunc |
| 96590 | + && sqlite3WalkExprList(pWalker, pItem->u1.pFuncArg) |
| 96591 | + ){ |
| 96592 | + return WRC_Abort; |
| 96593 | + } |
| 96569 | 96594 | } |
| 96570 | 96595 | } |
| 96571 | 96596 | return WRC_Continue; |
| 96572 | 96597 | } |
| 96573 | 96598 | |
| | @@ -96784,10 +96809,35 @@ |
| 96784 | 96809 | }else{ |
| 96785 | 96810 | /* Currently parsing a DML statement */ |
| 96786 | 96811 | return (db->flags & SQLITE_DqsDML)!=0; |
| 96787 | 96812 | } |
| 96788 | 96813 | } |
| 96814 | + |
| 96815 | +/* |
| 96816 | +** The argument is guaranteed to be a non-NULL Expr node of type TK_COLUMN. |
| 96817 | +** return the appropriate colUsed mask. |
| 96818 | +*/ |
| 96819 | +SQLITE_PRIVATE Bitmask sqlite3ExprColUsed(Expr *pExpr){ |
| 96820 | + int n; |
| 96821 | + Table *pExTab; |
| 96822 | + |
| 96823 | + n = pExpr->iColumn; |
| 96824 | + pExTab = pExpr->y.pTab; |
| 96825 | + assert( pExTab!=0 ); |
| 96826 | + if( (pExTab->tabFlags & TF_HasGenerated)!=0 |
| 96827 | + && (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0 |
| 96828 | + ){ |
| 96829 | + testcase( pExTab->nCol==BMS-1 ); |
| 96830 | + testcase( pExTab->nCol==BMS ); |
| 96831 | + return pExTab->nCol>=BMS ? ALLBITS : MASKBIT(pExTab->nCol)-1; |
| 96832 | + }else{ |
| 96833 | + testcase( n==BMS-1 ); |
| 96834 | + testcase( n==BMS ); |
| 96835 | + if( n>=BMS ) n = BMS-1; |
| 96836 | + return ((Bitmask)1)<<n; |
| 96837 | + } |
| 96838 | +} |
| 96789 | 96839 | |
| 96790 | 96840 | /* |
| 96791 | 96841 | ** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up |
| 96792 | 96842 | ** that name in the set of source tables in pSrcList and make the pExpr |
| 96793 | 96843 | ** expression node refer back to that source column. The following changes |
| | @@ -96861,10 +96911,16 @@ |
| 96861 | 96911 | assert( db->aDb[i].zDbSName ); |
| 96862 | 96912 | if( sqlite3StrICmp(db->aDb[i].zDbSName,zDb)==0 ){ |
| 96863 | 96913 | pSchema = db->aDb[i].pSchema; |
| 96864 | 96914 | break; |
| 96865 | 96915 | } |
| 96916 | + } |
| 96917 | + if( i==db->nDb && sqlite3StrICmp("main", zDb)==0 ){ |
| 96918 | + /* This branch is taken when the main database has been renamed |
| 96919 | + ** using SQLITE_DBCONFIG_MAINDBNAME. */ |
| 96920 | + pSchema = db->aDb[0].pSchema; |
| 96921 | + zDb = db->aDb[0].zDbSName; |
| 96866 | 96922 | } |
| 96867 | 96923 | } |
| 96868 | 96924 | } |
| 96869 | 96925 | |
| 96870 | 96926 | /* Start at the inner-most context and move outward until a match is found */ |
| | @@ -97181,26 +97237,11 @@ |
| 97181 | 97237 | ** |
| 97182 | 97238 | ** If a generated column is referenced, set bits for every column |
| 97183 | 97239 | ** of the table. |
| 97184 | 97240 | */ |
| 97185 | 97241 | if( pExpr->iColumn>=0 && pMatch!=0 ){ |
| 97186 | | - int n = pExpr->iColumn; |
| 97187 | | - Table *pExTab = pExpr->y.pTab; |
| 97188 | | - assert( pExTab!=0 ); |
| 97189 | | - assert( pMatch->iCursor==pExpr->iTable ); |
| 97190 | | - if( (pExTab->tabFlags & TF_HasGenerated)!=0 |
| 97191 | | - && (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0 |
| 97192 | | - ){ |
| 97193 | | - testcase( pExTab->nCol==BMS-1 ); |
| 97194 | | - testcase( pExTab->nCol==BMS ); |
| 97195 | | - pMatch->colUsed = pExTab->nCol>=BMS ? ALLBITS : MASKBIT(pExTab->nCol)-1; |
| 97196 | | - }else{ |
| 97197 | | - testcase( n==BMS-1 ); |
| 97198 | | - testcase( n==BMS ); |
| 97199 | | - if( n>=BMS ) n = BMS-1; |
| 97200 | | - pMatch->colUsed |= ((Bitmask)1)<<n; |
| 97201 | | - } |
| 97242 | + pMatch->colUsed |= sqlite3ExprColUsed(pExpr); |
| 97202 | 97243 | } |
| 97203 | 97244 | |
| 97204 | 97245 | /* Clean up and return |
| 97205 | 97246 | */ |
| 97206 | 97247 | sqlite3ExprDelete(db, pExpr->pLeft); |
| | @@ -98557,11 +98598,11 @@ |
| 98557 | 98598 | ** CREATE TABLE t1(a); |
| 98558 | 98599 | ** SELECT * FROM t1 WHERE a; |
| 98559 | 98600 | ** SELECT a AS b FROM t1 WHERE b; |
| 98560 | 98601 | ** SELECT * FROM t1 WHERE (select a from t1); |
| 98561 | 98602 | */ |
| 98562 | | -SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr){ |
| 98603 | +SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr){ |
| 98563 | 98604 | int op; |
| 98564 | 98605 | while( ExprHasProperty(pExpr, EP_Skip) ){ |
| 98565 | 98606 | assert( pExpr->op==TK_COLLATE ); |
| 98566 | 98607 | pExpr = pExpr->pLeft; |
| 98567 | 98608 | assert( pExpr!=0 ); |
| | @@ -98667,14 +98708,14 @@ |
| 98667 | 98708 | ** The collating sequence might be determined by a COLLATE operator |
| 98668 | 98709 | ** or by the presence of a column with a defined collating sequence. |
| 98669 | 98710 | ** COLLATE operators take first precedence. Left operands take |
| 98670 | 98711 | ** precedence over right operands. |
| 98671 | 98712 | */ |
| 98672 | | -SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){ |
| 98713 | +SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr){ |
| 98673 | 98714 | sqlite3 *db = pParse->db; |
| 98674 | 98715 | CollSeq *pColl = 0; |
| 98675 | | - Expr *p = pExpr; |
| 98716 | + const Expr *p = pExpr; |
| 98676 | 98717 | while( p ){ |
| 98677 | 98718 | int op = p->op; |
| 98678 | 98719 | if( op==TK_REGISTER ) op = p->op2; |
| 98679 | 98720 | if( (op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_TRIGGER) |
| 98680 | 98721 | && p->y.pTab!=0 |
| | @@ -98739,21 +98780,21 @@ |
| 98739 | 98780 | ** See also: sqlite3ExprCollSeq() |
| 98740 | 98781 | ** |
| 98741 | 98782 | ** The sqlite3ExprCollSeq() routine works the same except that it |
| 98742 | 98783 | ** returns NULL if there is no defined collation. |
| 98743 | 98784 | */ |
| 98744 | | -SQLITE_PRIVATE CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, Expr *pExpr){ |
| 98785 | +SQLITE_PRIVATE CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, const Expr *pExpr){ |
| 98745 | 98786 | CollSeq *p = sqlite3ExprCollSeq(pParse, pExpr); |
| 98746 | 98787 | if( p==0 ) p = pParse->db->pDfltColl; |
| 98747 | 98788 | assert( p!=0 ); |
| 98748 | 98789 | return p; |
| 98749 | 98790 | } |
| 98750 | 98791 | |
| 98751 | 98792 | /* |
| 98752 | 98793 | ** Return TRUE if the two expressions have equivalent collating sequences. |
| 98753 | 98794 | */ |
| 98754 | | -SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse *pParse, Expr *pE1, Expr *pE2){ |
| 98795 | +SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse *pParse, const Expr *pE1, const Expr *pE2){ |
| 98755 | 98796 | CollSeq *pColl1 = sqlite3ExprNNCollSeq(pParse, pE1); |
| 98756 | 98797 | CollSeq *pColl2 = sqlite3ExprNNCollSeq(pParse, pE2); |
| 98757 | 98798 | return sqlite3StrICmp(pColl1->zName, pColl2->zName)==0; |
| 98758 | 98799 | } |
| 98759 | 98800 | |
| | @@ -98760,11 +98801,11 @@ |
| 98760 | 98801 | /* |
| 98761 | 98802 | ** pExpr is an operand of a comparison operator. aff2 is the |
| 98762 | 98803 | ** type affinity of the other operand. This routine returns the |
| 98763 | 98804 | ** type affinity that should be used for the comparison operator. |
| 98764 | 98805 | */ |
| 98765 | | -SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2){ |
| 98806 | +SQLITE_PRIVATE char sqlite3CompareAffinity(const Expr *pExpr, char aff2){ |
| 98766 | 98807 | char aff1 = sqlite3ExprAffinity(pExpr); |
| 98767 | 98808 | if( aff1>SQLITE_AFF_NONE && aff2>SQLITE_AFF_NONE ){ |
| 98768 | 98809 | /* Both sides of the comparison are columns. If one has numeric |
| 98769 | 98810 | ** affinity, use that. Otherwise use no affinity. |
| 98770 | 98811 | */ |
| | @@ -98782,11 +98823,11 @@ |
| 98782 | 98823 | |
| 98783 | 98824 | /* |
| 98784 | 98825 | ** pExpr is a comparison operator. Return the type affinity that should |
| 98785 | 98826 | ** be applied to both operands prior to doing the comparison. |
| 98786 | 98827 | */ |
| 98787 | | -static char comparisonAffinity(Expr *pExpr){ |
| 98828 | +static char comparisonAffinity(const Expr *pExpr){ |
| 98788 | 98829 | char aff; |
| 98789 | 98830 | assert( pExpr->op==TK_EQ || pExpr->op==TK_IN || pExpr->op==TK_LT || |
| 98790 | 98831 | pExpr->op==TK_GT || pExpr->op==TK_GE || pExpr->op==TK_LE || |
| 98791 | 98832 | pExpr->op==TK_NE || pExpr->op==TK_IS || pExpr->op==TK_ISNOT ); |
| 98792 | 98833 | assert( pExpr->pLeft ); |
| | @@ -98805,11 +98846,11 @@ |
| 98805 | 98846 | ** pExpr is a comparison expression, eg. '=', '<', IN(...) etc. |
| 98806 | 98847 | ** idx_affinity is the affinity of an indexed column. Return true |
| 98807 | 98848 | ** if the index with affinity idx_affinity may be used to implement |
| 98808 | 98849 | ** the comparison in pExpr. |
| 98809 | 98850 | */ |
| 98810 | | -SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity){ |
| 98851 | +SQLITE_PRIVATE int sqlite3IndexAffinityOk(const Expr *pExpr, char idx_affinity){ |
| 98811 | 98852 | char aff = comparisonAffinity(pExpr); |
| 98812 | 98853 | if( aff<SQLITE_AFF_TEXT ){ |
| 98813 | 98854 | return 1; |
| 98814 | 98855 | } |
| 98815 | 98856 | if( aff==SQLITE_AFF_TEXT ){ |
| | @@ -98820,11 +98861,15 @@ |
| 98820 | 98861 | |
| 98821 | 98862 | /* |
| 98822 | 98863 | ** Return the P5 value that should be used for a binary comparison |
| 98823 | 98864 | ** opcode (OP_Eq, OP_Ge etc.) used to compare pExpr1 and pExpr2. |
| 98824 | 98865 | */ |
| 98825 | | -static u8 binaryCompareP5(Expr *pExpr1, Expr *pExpr2, int jumpIfNull){ |
| 98866 | +static u8 binaryCompareP5( |
| 98867 | + const Expr *pExpr1, /* Left operand */ |
| 98868 | + const Expr *pExpr2, /* Right operand */ |
| 98869 | + int jumpIfNull /* Extra flags added to P5 */ |
| 98870 | +){ |
| 98826 | 98871 | u8 aff = (char)sqlite3ExprAffinity(pExpr2); |
| 98827 | 98872 | aff = (u8)sqlite3CompareAffinity(pExpr1, aff) | (u8)jumpIfNull; |
| 98828 | 98873 | return aff; |
| 98829 | 98874 | } |
| 98830 | 98875 | |
| | @@ -98840,12 +98885,12 @@ |
| 98840 | 98885 | ** Argument pRight (but not pLeft) may be a null pointer. In this case, |
| 98841 | 98886 | ** it is not considered. |
| 98842 | 98887 | */ |
| 98843 | 98888 | SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq( |
| 98844 | 98889 | Parse *pParse, |
| 98845 | | - Expr *pLeft, |
| 98846 | | - Expr *pRight |
| 98890 | + const Expr *pLeft, |
| 98891 | + const Expr *pRight |
| 98847 | 98892 | ){ |
| 98848 | 98893 | CollSeq *pColl; |
| 98849 | 98894 | assert( pLeft ); |
| 98850 | 98895 | if( pLeft->flags & EP_Collate ){ |
| 98851 | 98896 | pColl = sqlite3ExprCollSeq(pParse, pLeft); |
| | @@ -98866,11 +98911,11 @@ |
| 98866 | 98911 | ** This is normally just a wrapper around sqlite3BinaryCompareCollSeq(). |
| 98867 | 98912 | ** However, if the OP_Commuted flag is set, then the order of the operands |
| 98868 | 98913 | ** is reversed in the sqlite3BinaryCompareCollSeq() call so that the |
| 98869 | 98914 | ** correct collating sequence is found. |
| 98870 | 98915 | */ |
| 98871 | | -SQLITE_PRIVATE CollSeq *sqlite3ExprCompareCollSeq(Parse *pParse, Expr *p){ |
| 98916 | +SQLITE_PRIVATE CollSeq *sqlite3ExprCompareCollSeq(Parse *pParse, const Expr *p){ |
| 98872 | 98917 | if( ExprHasProperty(p, EP_Commuted) ){ |
| 98873 | 98918 | return sqlite3BinaryCompareCollSeq(pParse, p->pRight, p->pLeft); |
| 98874 | 98919 | }else{ |
| 98875 | 98920 | return sqlite3BinaryCompareCollSeq(pParse, p->pLeft, p->pRight); |
| 98876 | 98921 | } |
| | @@ -99109,10 +99154,11 @@ |
| 99109 | 99154 | int regRight = 0; |
| 99110 | 99155 | u8 opx = op; |
| 99111 | 99156 | int addrDone = sqlite3VdbeMakeLabel(pParse); |
| 99112 | 99157 | int isCommuted = ExprHasProperty(pExpr,EP_Commuted); |
| 99113 | 99158 | |
| 99159 | + assert( !ExprHasVVAProperty(pExpr,EP_Immutable) ); |
| 99114 | 99160 | if( pParse->nErr ) return; |
| 99115 | 99161 | if( nLeft!=sqlite3ExprVectorSize(pRight) ){ |
| 99116 | 99162 | sqlite3ErrorMsg(pParse, "row value misused"); |
| 99117 | 99163 | return; |
| 99118 | 99164 | } |
| | @@ -99721,11 +99767,11 @@ |
| 99721 | 99767 | nSize = EXPR_FULLSIZE; |
| 99722 | 99768 | }else{ |
| 99723 | 99769 | assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) ); |
| 99724 | 99770 | assert( !ExprHasProperty(p, EP_FromJoin) ); |
| 99725 | 99771 | assert( !ExprHasProperty(p, EP_MemToken) ); |
| 99726 | | - assert( !ExprHasProperty(p, EP_NoReduce) ); |
| 99772 | + assert( !ExprHasVVAProperty(p, EP_NoReduce) ); |
| 99727 | 99773 | if( p->pLeft || p->x.pList ){ |
| 99728 | 99774 | nSize = EXPR_REDUCEDSIZE | EP_Reduced; |
| 99729 | 99775 | }else{ |
| 99730 | 99776 | assert( p->pRight==0 ); |
| 99731 | 99777 | nSize = EXPR_TOKENONLYSIZE | EP_TokenOnly; |
| | @@ -99826,10 +99872,14 @@ |
| 99826 | 99872 | |
| 99827 | 99873 | /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */ |
| 99828 | 99874 | pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken); |
| 99829 | 99875 | pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly); |
| 99830 | 99876 | pNew->flags |= staticFlag; |
| 99877 | + ExprClearVVAProperties(pNew); |
| 99878 | + if( dupFlags ){ |
| 99879 | + ExprSetVVAProperty(pNew, EP_Immutable); |
| 99880 | + } |
| 99831 | 99881 | |
| 99832 | 99882 | /* Copy the p->u.zToken string, if any. */ |
| 99833 | 99883 | if( nToken ){ |
| 99834 | 99884 | char *zToken = pNew->u.zToken = (char*)&zAlloc[nNewSize]; |
| 99835 | 99885 | memcpy(zToken, p->u.zToken, nToken); |
| | @@ -100602,11 +100652,11 @@ |
| 100602 | 100652 | ** (3) the expression does not contain any EP_FixedCol TK_COLUMN |
| 100603 | 100653 | ** operands created by the constant propagation optimization. |
| 100604 | 100654 | ** |
| 100605 | 100655 | ** When this routine returns true, it indicates that the expression |
| 100606 | 100656 | ** can be added to the pParse->pConstExpr list and evaluated once when |
| 100607 | | -** the prepared statement starts up. See sqlite3ExprCodeAtInit(). |
| 100657 | +** the prepared statement starts up. See sqlite3ExprCodeRunJustOnce(). |
| 100608 | 100658 | */ |
| 100609 | 100659 | SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr *p){ |
| 100610 | 100660 | return exprIsConst(p, 2, 0); |
| 100611 | 100661 | } |
| 100612 | 100662 | |
| | @@ -101365,10 +101415,11 @@ |
| 101365 | 101415 | return; |
| 101366 | 101416 | } |
| 101367 | 101417 | |
| 101368 | 101418 | /* Begin coding the subroutine */ |
| 101369 | 101419 | ExprSetProperty(pExpr, EP_Subrtn); |
| 101420 | + assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) ); |
| 101370 | 101421 | pExpr->y.sub.regReturn = ++pParse->nMem; |
| 101371 | 101422 | pExpr->y.sub.iAddr = |
| 101372 | 101423 | sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1; |
| 101373 | 101424 | VdbeComment((v, "return address")); |
| 101374 | 101425 | |
| | @@ -101685,10 +101736,11 @@ |
| 101685 | 101736 | int addrTruthOp; /* Address of opcode that determines the IN is true */ |
| 101686 | 101737 | int destNotNull; /* Jump here if a comparison is not true in step 6 */ |
| 101687 | 101738 | int addrTop; /* Top of the step-6 loop */ |
| 101688 | 101739 | int iTab = 0; /* Index to use */ |
| 101689 | 101740 | |
| 101741 | + assert( !ExprHasVVAProperty(pExpr,EP_Immutable) ); |
| 101690 | 101742 | pLeft = pExpr->pLeft; |
| 101691 | 101743 | if( sqlite3ExprCheckIN(pParse, pExpr) ) return; |
| 101692 | 101744 | zAff = exprINAffinity(pParse, pExpr); |
| 101693 | 101745 | nVector = sqlite3ExprVectorSize(pExpr->pLeft); |
| 101694 | 101746 | aiMap = (int*)sqlite3DbMallocZero( |
| | @@ -102011,11 +102063,11 @@ |
| 102011 | 102063 | if( pParse->iSelfTab>0 ){ |
| 102012 | 102064 | iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut); |
| 102013 | 102065 | }else{ |
| 102014 | 102066 | iAddr = 0; |
| 102015 | 102067 | } |
| 102016 | | - sqlite3ExprCode(pParse, pCol->pDflt, regOut); |
| 102068 | + sqlite3ExprCodeCopy(pParse, pCol->pDflt, regOut); |
| 102017 | 102069 | if( pCol->affinity>=SQLITE_AFF_TEXT ){ |
| 102018 | 102070 | sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1); |
| 102019 | 102071 | } |
| 102020 | 102072 | if( iAddr ) sqlite3VdbeJumpHere(v, iAddr); |
| 102021 | 102073 | } |
| | @@ -102295,10 +102347,11 @@ |
| 102295 | 102347 | |
| 102296 | 102348 | expr_code_doover: |
| 102297 | 102349 | if( pExpr==0 ){ |
| 102298 | 102350 | op = TK_NULL; |
| 102299 | 102351 | }else{ |
| 102352 | + assert( !ExprHasVVAProperty(pExpr,EP_Immutable) ); |
| 102300 | 102353 | op = pExpr->op; |
| 102301 | 102354 | } |
| 102302 | 102355 | switch( op ){ |
| 102303 | 102356 | case TK_AGG_COLUMN: { |
| 102304 | 102357 | AggInfo *pAggInfo = pExpr->pAggInfo; |
| | @@ -102305,12 +102358,21 @@ |
| 102305 | 102358 | struct AggInfo_col *pCol = &pAggInfo->aCol[pExpr->iAgg]; |
| 102306 | 102359 | if( !pAggInfo->directMode ){ |
| 102307 | 102360 | assert( pCol->iMem>0 ); |
| 102308 | 102361 | return pCol->iMem; |
| 102309 | 102362 | }else if( pAggInfo->useSortingIdx ){ |
| 102363 | + Table *pTab = pCol->pTab; |
| 102310 | 102364 | sqlite3VdbeAddOp3(v, OP_Column, pAggInfo->sortingIdxPTab, |
| 102311 | 102365 | pCol->iSorterColumn, target); |
| 102366 | + if( pCol->iColumn<0 ){ |
| 102367 | + VdbeComment((v,"%s.rowid",pTab->zName)); |
| 102368 | + }else{ |
| 102369 | + VdbeComment((v,"%s.%s",pTab->zName,pTab->aCol[pCol->iColumn].zName)); |
| 102370 | + if( pTab->aCol[pCol->iColumn].affinity==SQLITE_AFF_REAL ){ |
| 102371 | + sqlite3VdbeAddOp1(v, OP_RealAffinity, target); |
| 102372 | + } |
| 102373 | + } |
| 102312 | 102374 | return target; |
| 102313 | 102375 | } |
| 102314 | 102376 | /* Otherwise, fall thru into the TK_COLUMN case */ |
| 102315 | 102377 | } |
| 102316 | 102378 | case TK_COLUMN: { |
| | @@ -102549,10 +102611,11 @@ |
| 102549 | 102611 | #endif |
| 102550 | 102612 | }else{ |
| 102551 | 102613 | tempX.op = TK_INTEGER; |
| 102552 | 102614 | tempX.flags = EP_IntValue|EP_TokenOnly; |
| 102553 | 102615 | tempX.u.iValue = 0; |
| 102616 | + ExprClearVVAProperties(&tempX); |
| 102554 | 102617 | r1 = sqlite3ExprCodeTemp(pParse, &tempX, ®Free1); |
| 102555 | 102618 | r2 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free2); |
| 102556 | 102619 | sqlite3VdbeAddOp3(v, OP_Subtract, r2, r1, target); |
| 102557 | 102620 | testcase( regFree2==0 ); |
| 102558 | 102621 | } |
| | @@ -102620,20 +102683,17 @@ |
| 102620 | 102683 | return pExpr->y.pWin->regResult; |
| 102621 | 102684 | } |
| 102622 | 102685 | #endif |
| 102623 | 102686 | |
| 102624 | 102687 | if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){ |
| 102625 | | - /* SQL functions can be expensive. So try to move constant functions |
| 102626 | | - ** out of the inner loop, even if that means an extra OP_Copy. */ |
| 102627 | | - return sqlite3ExprCodeAtInit(pParse, pExpr, -1); |
| 102688 | + /* SQL functions can be expensive. So try to avoid running them |
| 102689 | + ** multiple times if we know they always give the same result */ |
| 102690 | + return sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1); |
| 102628 | 102691 | } |
| 102629 | 102692 | assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 102630 | | - if( ExprHasProperty(pExpr, EP_TokenOnly) ){ |
| 102631 | | - pFarg = 0; |
| 102632 | | - }else{ |
| 102633 | | - pFarg = pExpr->x.pList; |
| 102634 | | - } |
| 102693 | + assert( !ExprHasProperty(pExpr, EP_TokenOnly) ); |
| 102694 | + pFarg = pExpr->x.pList; |
| 102635 | 102695 | nFarg = pFarg ? pFarg->nExpr : 0; |
| 102636 | 102696 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 102637 | 102697 | zId = pExpr->u.zToken; |
| 102638 | 102698 | pDef = sqlite3FindFunction(db, zId, nFarg, enc, 0); |
| 102639 | 102699 | #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| | @@ -103003,19 +103063,27 @@ |
| 103003 | 103063 | sqlite3ReleaseTempReg(pParse, regFree2); |
| 103004 | 103064 | return inReg; |
| 103005 | 103065 | } |
| 103006 | 103066 | |
| 103007 | 103067 | /* |
| 103008 | | -** Factor out the code of the given expression to initialization time. |
| 103068 | +** Generate code that will evaluate expression pExpr just one time |
| 103069 | +** per prepared statement execution. |
| 103070 | +** |
| 103071 | +** If the expression uses functions (that might throw an exception) then |
| 103072 | +** guard them with an OP_Once opcode to ensure that the code is only executed |
| 103073 | +** once. If no functions are involved, then factor the code out and put it at |
| 103074 | +** the end of the prepared statement in the initialization section. |
| 103009 | 103075 | ** |
| 103010 | 103076 | ** If regDest>=0 then the result is always stored in that register and the |
| 103011 | 103077 | ** result is not reusable. If regDest<0 then this routine is free to |
| 103012 | 103078 | ** store the value whereever it wants. The register where the expression |
| 103013 | | -** is stored is returned. When regDest<0, two identical expressions will |
| 103014 | | -** code to the same register. |
| 103079 | +** is stored is returned. When regDest<0, two identical expressions might |
| 103080 | +** code to the same register, if they do not contain function calls and hence |
| 103081 | +** are factored out into the initialization section at the end of the |
| 103082 | +** prepared statement. |
| 103015 | 103083 | */ |
| 103016 | | -SQLITE_PRIVATE int sqlite3ExprCodeAtInit( |
| 103084 | +SQLITE_PRIVATE int sqlite3ExprCodeRunJustOnce( |
| 103017 | 103085 | Parse *pParse, /* Parsing context */ |
| 103018 | 103086 | Expr *pExpr, /* The expression to code when the VDBE initializes */ |
| 103019 | 103087 | int regDest /* Store the value in this register */ |
| 103020 | 103088 | ){ |
| 103021 | 103089 | ExprList *p; |
| | @@ -103029,18 +103097,33 @@ |
| 103029 | 103097 | return pItem->u.iConstExprReg; |
| 103030 | 103098 | } |
| 103031 | 103099 | } |
| 103032 | 103100 | } |
| 103033 | 103101 | pExpr = sqlite3ExprDup(pParse->db, pExpr, 0); |
| 103034 | | - p = sqlite3ExprListAppend(pParse, p, pExpr); |
| 103035 | | - if( p ){ |
| 103036 | | - struct ExprList_item *pItem = &p->a[p->nExpr-1]; |
| 103037 | | - pItem->reusable = regDest<0; |
| 103038 | | - if( regDest<0 ) regDest = ++pParse->nMem; |
| 103039 | | - pItem->u.iConstExprReg = regDest; |
| 103040 | | - } |
| 103041 | | - pParse->pConstExpr = p; |
| 103102 | + if( pExpr!=0 && ExprHasProperty(pExpr, EP_HasFunc) ){ |
| 103103 | + Vdbe *v = pParse->pVdbe; |
| 103104 | + int addr; |
| 103105 | + assert( v ); |
| 103106 | + addr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); |
| 103107 | + pParse->okConstFactor = 0; |
| 103108 | + if( !pParse->db->mallocFailed ){ |
| 103109 | + if( regDest<0 ) regDest = ++pParse->nMem; |
| 103110 | + sqlite3ExprCode(pParse, pExpr, regDest); |
| 103111 | + } |
| 103112 | + pParse->okConstFactor = 1; |
| 103113 | + sqlite3ExprDelete(pParse->db, pExpr); |
| 103114 | + sqlite3VdbeJumpHere(v, addr); |
| 103115 | + }else{ |
| 103116 | + p = sqlite3ExprListAppend(pParse, p, pExpr); |
| 103117 | + if( p ){ |
| 103118 | + struct ExprList_item *pItem = &p->a[p->nExpr-1]; |
| 103119 | + pItem->reusable = regDest<0; |
| 103120 | + if( regDest<0 ) regDest = ++pParse->nMem; |
| 103121 | + pItem->u.iConstExprReg = regDest; |
| 103122 | + } |
| 103123 | + pParse->pConstExpr = p; |
| 103124 | + } |
| 103042 | 103125 | return regDest; |
| 103043 | 103126 | } |
| 103044 | 103127 | |
| 103045 | 103128 | /* |
| 103046 | 103129 | ** Generate code to evaluate an expression and store the results |
| | @@ -103061,11 +103144,11 @@ |
| 103061 | 103144 | if( ConstFactorOk(pParse) |
| 103062 | 103145 | && pExpr->op!=TK_REGISTER |
| 103063 | 103146 | && sqlite3ExprIsConstantNotJoin(pExpr) |
| 103064 | 103147 | ){ |
| 103065 | 103148 | *pReg = 0; |
| 103066 | | - r2 = sqlite3ExprCodeAtInit(pParse, pExpr, -1); |
| 103149 | + r2 = sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1); |
| 103067 | 103150 | }else{ |
| 103068 | 103151 | int r1 = sqlite3GetTempReg(pParse); |
| 103069 | 103152 | r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1); |
| 103070 | 103153 | if( r2==r1 ){ |
| 103071 | 103154 | *pReg = r1; |
| | @@ -103083,10 +103166,11 @@ |
| 103083 | 103166 | ** in register target. |
| 103084 | 103167 | */ |
| 103085 | 103168 | SQLITE_PRIVATE void sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){ |
| 103086 | 103169 | int inReg; |
| 103087 | 103170 | |
| 103171 | + assert( pExpr==0 || !ExprHasVVAProperty(pExpr,EP_Immutable) ); |
| 103088 | 103172 | assert( target>0 && target<=pParse->nMem ); |
| 103089 | 103173 | inReg = sqlite3ExprCodeTarget(pParse, pExpr, target); |
| 103090 | 103174 | assert( pParse->pVdbe!=0 || pParse->db->mallocFailed ); |
| 103091 | 103175 | if( inReg!=target && pParse->pVdbe ){ |
| 103092 | 103176 | u8 op; |
| | @@ -103117,13 +103201,13 @@ |
| 103117 | 103201 | ** in register target. If the expression is constant, then this routine |
| 103118 | 103202 | ** might choose to code the expression at initialization time. |
| 103119 | 103203 | */ |
| 103120 | 103204 | SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse *pParse, Expr *pExpr, int target){ |
| 103121 | 103205 | if( pParse->okConstFactor && sqlite3ExprIsConstantNotJoin(pExpr) ){ |
| 103122 | | - sqlite3ExprCodeAtInit(pParse, pExpr, target); |
| 103206 | + sqlite3ExprCodeRunJustOnce(pParse, pExpr, target); |
| 103123 | 103207 | }else{ |
| 103124 | | - sqlite3ExprCode(pParse, pExpr, target); |
| 103208 | + sqlite3ExprCodeCopy(pParse, pExpr, target); |
| 103125 | 103209 | } |
| 103126 | 103210 | } |
| 103127 | 103211 | |
| 103128 | 103212 | /* |
| 103129 | 103213 | ** Generate code that pushes the value of every element of the given |
| | @@ -103177,11 +103261,11 @@ |
| 103177 | 103261 | sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i); |
| 103178 | 103262 | } |
| 103179 | 103263 | }else if( (flags & SQLITE_ECEL_FACTOR)!=0 |
| 103180 | 103264 | && sqlite3ExprIsConstantNotJoin(pExpr) |
| 103181 | 103265 | ){ |
| 103182 | | - sqlite3ExprCodeAtInit(pParse, pExpr, target+i); |
| 103266 | + sqlite3ExprCodeRunJustOnce(pParse, pExpr, target+i); |
| 103183 | 103267 | }else{ |
| 103184 | 103268 | int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i); |
| 103185 | 103269 | if( inReg!=target+i ){ |
| 103186 | 103270 | VdbeOp *pOp; |
| 103187 | 103271 | if( copyOp==OP_Copy |
| | @@ -103300,10 +103384,11 @@ |
| 103300 | 103384 | int r1, r2; |
| 103301 | 103385 | |
| 103302 | 103386 | assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 ); |
| 103303 | 103387 | if( NEVER(v==0) ) return; /* Existence of VDBE checked by caller */ |
| 103304 | 103388 | if( NEVER(pExpr==0) ) return; /* No way this can happen */ |
| 103389 | + assert( !ExprHasVVAProperty(pExpr, EP_Immutable) ); |
| 103305 | 103390 | op = pExpr->op; |
| 103306 | 103391 | switch( op ){ |
| 103307 | 103392 | case TK_AND: |
| 103308 | 103393 | case TK_OR: { |
| 103309 | 103394 | Expr *pAlt = sqlite3ExprSimplifiedAndOr(pExpr); |
| | @@ -103441,10 +103526,11 @@ |
| 103441 | 103526 | int r1, r2; |
| 103442 | 103527 | |
| 103443 | 103528 | assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 ); |
| 103444 | 103529 | if( NEVER(v==0) ) return; /* Existence of VDBE checked by caller */ |
| 103445 | 103530 | if( pExpr==0 ) return; |
| 103531 | + assert( !ExprHasVVAProperty(pExpr,EP_Immutable) ); |
| 103446 | 103532 | |
| 103447 | 103533 | /* The value of pExpr->op and op are related as follows: |
| 103448 | 103534 | ** |
| 103449 | 103535 | ** pExpr->op op |
| 103450 | 103536 | ** --------- ---------- |
| | @@ -103724,36 +103810,22 @@ |
| 103724 | 103810 | return 2; |
| 103725 | 103811 | } |
| 103726 | 103812 | } |
| 103727 | 103813 | if( (pA->flags & (EP_Distinct|EP_Commuted)) |
| 103728 | 103814 | != (pB->flags & (EP_Distinct|EP_Commuted)) ) return 2; |
| 103729 | | - if( (combinedFlags & EP_TokenOnly)==0 ){ |
| 103815 | + if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){ |
| 103730 | 103816 | if( combinedFlags & EP_xIsSelect ) return 2; |
| 103731 | 103817 | if( (combinedFlags & EP_FixedCol)==0 |
| 103732 | 103818 | && sqlite3ExprCompare(pParse, pA->pLeft, pB->pLeft, iTab) ) return 2; |
| 103733 | 103819 | if( sqlite3ExprCompare(pParse, pA->pRight, pB->pRight, iTab) ) return 2; |
| 103734 | 103820 | if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2; |
| 103735 | 103821 | if( pA->op!=TK_STRING |
| 103736 | 103822 | && pA->op!=TK_TRUEFALSE |
| 103737 | | - && (combinedFlags & EP_Reduced)==0 |
| 103823 | + && ALWAYS((combinedFlags & EP_Reduced)==0) |
| 103738 | 103824 | ){ |
| 103739 | 103825 | if( pA->iColumn!=pB->iColumn ) return 2; |
| 103740 | | - if( pA->op2!=pB->op2 ){ |
| 103741 | | - if( pA->op==TK_TRUTH ) return 2; |
| 103742 | | - if( pA->op==TK_FUNCTION && iTab<0 ){ |
| 103743 | | - /* Ex: CREATE TABLE t1(a CHECK( a<julianday('now') )); |
| 103744 | | - ** INSERT INTO t1(a) VALUES(julianday('now')+10); |
| 103745 | | - ** Without this test, sqlite3ExprCodeAtInit() will run on the |
| 103746 | | - ** the julianday() of INSERT first, and remember that expression. |
| 103747 | | - ** Then sqlite3ExprCodeInit() will see the julianday() in the CHECK |
| 103748 | | - ** constraint as redundant, reusing the one from the INSERT, even |
| 103749 | | - ** though the julianday() in INSERT lacks the critical NC_IsCheck |
| 103750 | | - ** flag. See ticket [830277d9db6c3ba1] (2019-10-30) |
| 103751 | | - */ |
| 103752 | | - return 2; |
| 103753 | | - } |
| 103754 | | - } |
| 103826 | + if( pA->op2!=pB->op2 && pA->op==TK_TRUTH ) return 2; |
| 103755 | 103827 | if( pA->op!=TK_IN && pA->iTable!=pB->iTable && pA->iTable!=iTab ){ |
| 103756 | 103828 | return 2; |
| 103757 | 103829 | } |
| 103758 | 103830 | } |
| 103759 | 103831 | } |
| | @@ -106442,13 +106514,13 @@ |
| 106442 | 106514 | /* |
| 106443 | 106515 | ** Three SQL functions - stat_init(), stat_push(), and stat_get() - |
| 106444 | 106516 | ** share an instance of the following structure to hold their state |
| 106445 | 106517 | ** information. |
| 106446 | 106518 | */ |
| 106447 | | -typedef struct Stat4Accum Stat4Accum; |
| 106448 | | -typedef struct Stat4Sample Stat4Sample; |
| 106449 | | -struct Stat4Sample { |
| 106519 | +typedef struct StatAccum StatAccum; |
| 106520 | +typedef struct StatSample StatSample; |
| 106521 | +struct StatSample { |
| 106450 | 106522 | tRowcnt *anEq; /* sqlite_stat4.nEq */ |
| 106451 | 106523 | tRowcnt *anDLt; /* sqlite_stat4.nDLt */ |
| 106452 | 106524 | #ifdef SQLITE_ENABLE_STAT4 |
| 106453 | 106525 | tRowcnt *anLt; /* sqlite_stat4.nLt */ |
| 106454 | 106526 | union { |
| | @@ -106459,31 +106531,33 @@ |
| 106459 | 106531 | u8 isPSample; /* True if a periodic sample */ |
| 106460 | 106532 | int iCol; /* If !isPSample, the reason for inclusion */ |
| 106461 | 106533 | u32 iHash; /* Tiebreaker hash */ |
| 106462 | 106534 | #endif |
| 106463 | 106535 | }; |
| 106464 | | -struct Stat4Accum { |
| 106536 | +struct StatAccum { |
| 106537 | + sqlite3 *db; /* Database connection, for malloc() */ |
| 106465 | 106538 | tRowcnt nRow; /* Number of rows in the entire table */ |
| 106466 | | - tRowcnt nPSample; /* How often to do a periodic sample */ |
| 106467 | 106539 | int nCol; /* Number of columns in index + pk/rowid */ |
| 106468 | 106540 | int nKeyCol; /* Number of index columns w/o the pk/rowid */ |
| 106541 | + StatSample current; /* Current row as a StatSample */ |
| 106542 | +#ifdef SQLITE_ENABLE_STAT4 |
| 106543 | + tRowcnt nPSample; /* How often to do a periodic sample */ |
| 106469 | 106544 | int mxSample; /* Maximum number of samples to accumulate */ |
| 106470 | | - Stat4Sample current; /* Current row as a Stat4Sample */ |
| 106471 | 106545 | u32 iPrn; /* Pseudo-random number used for sampling */ |
| 106472 | | - Stat4Sample *aBest; /* Array of nCol best samples */ |
| 106546 | + StatSample *aBest; /* Array of nCol best samples */ |
| 106473 | 106547 | int iMin; /* Index in a[] of entry with minimum score */ |
| 106474 | 106548 | int nSample; /* Current number of samples */ |
| 106475 | 106549 | int nMaxEqZero; /* Max leading 0 in anEq[] for any a[] entry */ |
| 106476 | 106550 | int iGet; /* Index of current sample accessed by stat_get() */ |
| 106477 | | - Stat4Sample *a; /* Array of mxSample Stat4Sample objects */ |
| 106478 | | - sqlite3 *db; /* Database connection, for malloc() */ |
| 106551 | + StatSample *a; /* Array of mxSample StatSample objects */ |
| 106552 | +#endif |
| 106479 | 106553 | }; |
| 106480 | 106554 | |
| 106481 | | -/* Reclaim memory used by a Stat4Sample |
| 106555 | +/* Reclaim memory used by a StatSample |
| 106482 | 106556 | */ |
| 106483 | 106557 | #ifdef SQLITE_ENABLE_STAT4 |
| 106484 | | -static void sampleClear(sqlite3 *db, Stat4Sample *p){ |
| 106558 | +static void sampleClear(sqlite3 *db, StatSample *p){ |
| 106485 | 106559 | assert( db!=0 ); |
| 106486 | 106560 | if( p->nRowid ){ |
| 106487 | 106561 | sqlite3DbFree(db, p->u.aRowid); |
| 106488 | 106562 | p->nRowid = 0; |
| 106489 | 106563 | } |
| | @@ -106491,11 +106565,11 @@ |
| 106491 | 106565 | #endif |
| 106492 | 106566 | |
| 106493 | 106567 | /* Initialize the BLOB value of a ROWID |
| 106494 | 106568 | */ |
| 106495 | 106569 | #ifdef SQLITE_ENABLE_STAT4 |
| 106496 | | -static void sampleSetRowid(sqlite3 *db, Stat4Sample *p, int n, const u8 *pData){ |
| 106570 | +static void sampleSetRowid(sqlite3 *db, StatSample *p, int n, const u8 *pData){ |
| 106497 | 106571 | assert( db!=0 ); |
| 106498 | 106572 | if( p->nRowid ) sqlite3DbFree(db, p->u.aRowid); |
| 106499 | 106573 | p->u.aRowid = sqlite3DbMallocRawNN(db, n); |
| 106500 | 106574 | if( p->u.aRowid ){ |
| 106501 | 106575 | p->nRowid = n; |
| | @@ -106507,11 +106581,11 @@ |
| 106507 | 106581 | #endif |
| 106508 | 106582 | |
| 106509 | 106583 | /* Initialize the INTEGER value of a ROWID. |
| 106510 | 106584 | */ |
| 106511 | 106585 | #ifdef SQLITE_ENABLE_STAT4 |
| 106512 | | -static void sampleSetRowidInt64(sqlite3 *db, Stat4Sample *p, i64 iRowid){ |
| 106586 | +static void sampleSetRowidInt64(sqlite3 *db, StatSample *p, i64 iRowid){ |
| 106513 | 106587 | assert( db!=0 ); |
| 106514 | 106588 | if( p->nRowid ) sqlite3DbFree(db, p->u.aRowid); |
| 106515 | 106589 | p->nRowid = 0; |
| 106516 | 106590 | p->u.iRowid = iRowid; |
| 106517 | 106591 | } |
| | @@ -106520,11 +106594,11 @@ |
| 106520 | 106594 | |
| 106521 | 106595 | /* |
| 106522 | 106596 | ** Copy the contents of object (*pFrom) into (*pTo). |
| 106523 | 106597 | */ |
| 106524 | 106598 | #ifdef SQLITE_ENABLE_STAT4 |
| 106525 | | -static void sampleCopy(Stat4Accum *p, Stat4Sample *pTo, Stat4Sample *pFrom){ |
| 106599 | +static void sampleCopy(StatAccum *p, StatSample *pTo, StatSample *pFrom){ |
| 106526 | 106600 | pTo->isPSample = pFrom->isPSample; |
| 106527 | 106601 | pTo->iCol = pFrom->iCol; |
| 106528 | 106602 | pTo->iHash = pFrom->iHash; |
| 106529 | 106603 | memcpy(pTo->anEq, pFrom->anEq, sizeof(tRowcnt)*p->nCol); |
| 106530 | 106604 | memcpy(pTo->anLt, pFrom->anLt, sizeof(tRowcnt)*p->nCol); |
| | @@ -106536,14 +106610,14 @@ |
| 106536 | 106610 | } |
| 106537 | 106611 | } |
| 106538 | 106612 | #endif |
| 106539 | 106613 | |
| 106540 | 106614 | /* |
| 106541 | | -** Reclaim all memory of a Stat4Accum structure. |
| 106615 | +** Reclaim all memory of a StatAccum structure. |
| 106542 | 106616 | */ |
| 106543 | | -static void stat4Destructor(void *pOld){ |
| 106544 | | - Stat4Accum *p = (Stat4Accum*)pOld; |
| 106617 | +static void statAccumDestructor(void *pOld){ |
| 106618 | + StatAccum *p = (StatAccum*)pOld; |
| 106545 | 106619 | #ifdef SQLITE_ENABLE_STAT4 |
| 106546 | 106620 | int i; |
| 106547 | 106621 | for(i=0; i<p->nCol; i++) sampleClear(p->db, p->aBest+i); |
| 106548 | 106622 | for(i=0; i<p->mxSample; i++) sampleClear(p->db, p->a+i); |
| 106549 | 106623 | sampleClear(p->db, &p->current); |
| | @@ -106567,21 +106641,21 @@ |
| 106567 | 106641 | ** For indexes on ordinary rowid tables, N==K+1. But for indexes on |
| 106568 | 106642 | ** WITHOUT ROWID tables, N=K+P where P is the number of columns in the |
| 106569 | 106643 | ** PRIMARY KEY of the table. The covering index that implements the |
| 106570 | 106644 | ** original WITHOUT ROWID table as N==K as a special case. |
| 106571 | 106645 | ** |
| 106572 | | -** This routine allocates the Stat4Accum object in heap memory. The return |
| 106573 | | -** value is a pointer to the Stat4Accum object. The datatype of the |
| 106574 | | -** return value is BLOB, but it is really just a pointer to the Stat4Accum |
| 106646 | +** This routine allocates the StatAccum object in heap memory. The return |
| 106647 | +** value is a pointer to the StatAccum object. The datatype of the |
| 106648 | +** return value is BLOB, but it is really just a pointer to the StatAccum |
| 106575 | 106649 | ** object. |
| 106576 | 106650 | */ |
| 106577 | 106651 | static void statInit( |
| 106578 | 106652 | sqlite3_context *context, |
| 106579 | 106653 | int argc, |
| 106580 | 106654 | sqlite3_value **argv |
| 106581 | 106655 | ){ |
| 106582 | | - Stat4Accum *p; |
| 106656 | + StatAccum *p; |
| 106583 | 106657 | int nCol; /* Number of columns in index being sampled */ |
| 106584 | 106658 | int nKeyCol; /* Number of key columns */ |
| 106585 | 106659 | int nColUp; /* nCol rounded up for alignment */ |
| 106586 | 106660 | int n; /* Bytes of space to allocate */ |
| 106587 | 106661 | sqlite3 *db; /* Database connection */ |
| | @@ -106596,17 +106670,17 @@ |
| 106596 | 106670 | nColUp = sizeof(tRowcnt)<8 ? (nCol+1)&~1 : nCol; |
| 106597 | 106671 | nKeyCol = sqlite3_value_int(argv[1]); |
| 106598 | 106672 | assert( nKeyCol<=nCol ); |
| 106599 | 106673 | assert( nKeyCol>0 ); |
| 106600 | 106674 | |
| 106601 | | - /* Allocate the space required for the Stat4Accum object */ |
| 106675 | + /* Allocate the space required for the StatAccum object */ |
| 106602 | 106676 | n = sizeof(*p) |
| 106603 | | - + sizeof(tRowcnt)*nColUp /* Stat4Accum.anEq */ |
| 106604 | | - + sizeof(tRowcnt)*nColUp /* Stat4Accum.anDLt */ |
| 106677 | + + sizeof(tRowcnt)*nColUp /* StatAccum.anEq */ |
| 106678 | + + sizeof(tRowcnt)*nColUp /* StatAccum.anDLt */ |
| 106605 | 106679 | #ifdef SQLITE_ENABLE_STAT4 |
| 106606 | | - + sizeof(tRowcnt)*nColUp /* Stat4Accum.anLt */ |
| 106607 | | - + sizeof(Stat4Sample)*(nCol+mxSample) /* Stat4Accum.aBest[], a[] */ |
| 106680 | + + sizeof(tRowcnt)*nColUp /* StatAccum.anLt */ |
| 106681 | + + sizeof(StatSample)*(nCol+mxSample) /* StatAccum.aBest[], a[] */ |
| 106608 | 106682 | + sizeof(tRowcnt)*3*nColUp*(nCol+mxSample) |
| 106609 | 106683 | #endif |
| 106610 | 106684 | ; |
| 106611 | 106685 | db = sqlite3_context_db_handle(context); |
| 106612 | 106686 | p = sqlite3DbMallocZero(db, n); |
| | @@ -106631,12 +106705,12 @@ |
| 106631 | 106705 | p->mxSample = mxSample; |
| 106632 | 106706 | p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[2])/(mxSample/3+1) + 1); |
| 106633 | 106707 | p->current.anLt = &p->current.anEq[nColUp]; |
| 106634 | 106708 | p->iPrn = 0x689e962d*(u32)nCol ^ 0xd0944565*(u32)sqlite3_value_int(argv[2]); |
| 106635 | 106709 | |
| 106636 | | - /* Set up the Stat4Accum.a[] and aBest[] arrays */ |
| 106637 | | - p->a = (struct Stat4Sample*)&p->current.anLt[nColUp]; |
| 106710 | + /* Set up the StatAccum.a[] and aBest[] arrays */ |
| 106711 | + p->a = (struct StatSample*)&p->current.anLt[nColUp]; |
| 106638 | 106712 | p->aBest = &p->a[mxSample]; |
| 106639 | 106713 | pSpace = (u8*)(&p->a[mxSample+nCol]); |
| 106640 | 106714 | for(i=0; i<(mxSample+nCol); i++){ |
| 106641 | 106715 | p->a[i].anEq = (tRowcnt *)pSpace; pSpace += (sizeof(tRowcnt) * nColUp); |
| 106642 | 106716 | p->a[i].anLt = (tRowcnt *)pSpace; pSpace += (sizeof(tRowcnt) * nColUp); |
| | @@ -106652,11 +106726,11 @@ |
| 106652 | 106726 | |
| 106653 | 106727 | /* Return a pointer to the allocated object to the caller. Note that |
| 106654 | 106728 | ** only the pointer (the 2nd parameter) matters. The size of the object |
| 106655 | 106729 | ** (given by the 3rd parameter) is never used and can be any positive |
| 106656 | 106730 | ** value. */ |
| 106657 | | - sqlite3_result_blob(context, p, sizeof(*p), stat4Destructor); |
| 106731 | + sqlite3_result_blob(context, p, sizeof(*p), statAccumDestructor); |
| 106658 | 106732 | } |
| 106659 | 106733 | static const FuncDef statInitFuncdef = { |
| 106660 | 106734 | 2+IsStat4, /* nArg */ |
| 106661 | 106735 | SQLITE_UTF8, /* funcFlags */ |
| 106662 | 106736 | 0, /* pUserData */ |
| | @@ -106679,13 +106753,13 @@ |
| 106679 | 106753 | ** |
| 106680 | 106754 | ** This function assumes that for each argument sample, the contents of |
| 106681 | 106755 | ** the anEq[] array from pSample->anEq[pSample->iCol+1] onwards are valid. |
| 106682 | 106756 | */ |
| 106683 | 106757 | static int sampleIsBetterPost( |
| 106684 | | - Stat4Accum *pAccum, |
| 106685 | | - Stat4Sample *pNew, |
| 106686 | | - Stat4Sample *pOld |
| 106758 | + StatAccum *pAccum, |
| 106759 | + StatSample *pNew, |
| 106760 | + StatSample *pOld |
| 106687 | 106761 | ){ |
| 106688 | 106762 | int nCol = pAccum->nCol; |
| 106689 | 106763 | int i; |
| 106690 | 106764 | assert( pNew->iCol==pOld->iCol ); |
| 106691 | 106765 | for(i=pNew->iCol+1; i<nCol; i++){ |
| | @@ -106703,13 +106777,13 @@ |
| 106703 | 106777 | ** |
| 106704 | 106778 | ** This function assumes that for each argument sample, the contents of |
| 106705 | 106779 | ** the anEq[] array from pSample->anEq[pSample->iCol] onwards are valid. |
| 106706 | 106780 | */ |
| 106707 | 106781 | static int sampleIsBetter( |
| 106708 | | - Stat4Accum *pAccum, |
| 106709 | | - Stat4Sample *pNew, |
| 106710 | | - Stat4Sample *pOld |
| 106782 | + StatAccum *pAccum, |
| 106783 | + StatSample *pNew, |
| 106784 | + StatSample *pOld |
| 106711 | 106785 | ){ |
| 106712 | 106786 | tRowcnt nEqNew = pNew->anEq[pNew->iCol]; |
| 106713 | 106787 | tRowcnt nEqOld = pOld->anEq[pOld->iCol]; |
| 106714 | 106788 | |
| 106715 | 106789 | assert( pOld->isPSample==0 && pNew->isPSample==0 ); |
| | @@ -106725,34 +106799,34 @@ |
| 106725 | 106799 | |
| 106726 | 106800 | /* |
| 106727 | 106801 | ** Copy the contents of sample *pNew into the p->a[] array. If necessary, |
| 106728 | 106802 | ** remove the least desirable sample from p->a[] to make room. |
| 106729 | 106803 | */ |
| 106730 | | -static void sampleInsert(Stat4Accum *p, Stat4Sample *pNew, int nEqZero){ |
| 106731 | | - Stat4Sample *pSample = 0; |
| 106804 | +static void sampleInsert(StatAccum *p, StatSample *pNew, int nEqZero){ |
| 106805 | + StatSample *pSample = 0; |
| 106732 | 106806 | int i; |
| 106733 | 106807 | |
| 106734 | 106808 | assert( IsStat4 || nEqZero==0 ); |
| 106735 | 106809 | |
| 106736 | | - /* Stat4Accum.nMaxEqZero is set to the maximum number of leading 0 |
| 106737 | | - ** values in the anEq[] array of any sample in Stat4Accum.a[]. In |
| 106810 | + /* StatAccum.nMaxEqZero is set to the maximum number of leading 0 |
| 106811 | + ** values in the anEq[] array of any sample in StatAccum.a[]. In |
| 106738 | 106812 | ** other words, if nMaxEqZero is n, then it is guaranteed that there |
| 106739 | | - ** are no samples with Stat4Sample.anEq[m]==0 for (m>=n). */ |
| 106813 | + ** are no samples with StatSample.anEq[m]==0 for (m>=n). */ |
| 106740 | 106814 | if( nEqZero>p->nMaxEqZero ){ |
| 106741 | 106815 | p->nMaxEqZero = nEqZero; |
| 106742 | 106816 | } |
| 106743 | 106817 | if( pNew->isPSample==0 ){ |
| 106744 | | - Stat4Sample *pUpgrade = 0; |
| 106818 | + StatSample *pUpgrade = 0; |
| 106745 | 106819 | assert( pNew->anEq[pNew->iCol]>0 ); |
| 106746 | 106820 | |
| 106747 | 106821 | /* This sample is being added because the prefix that ends in column |
| 106748 | 106822 | ** iCol occurs many times in the table. However, if we have already |
| 106749 | 106823 | ** added a sample that shares this prefix, there is no need to add |
| 106750 | 106824 | ** this one. Instead, upgrade the priority of the highest priority |
| 106751 | 106825 | ** existing sample that shares this prefix. */ |
| 106752 | 106826 | for(i=p->nSample-1; i>=0; i--){ |
| 106753 | | - Stat4Sample *pOld = &p->a[i]; |
| 106827 | + StatSample *pOld = &p->a[i]; |
| 106754 | 106828 | if( pOld->anEq[pNew->iCol]==0 ){ |
| 106755 | 106829 | if( pOld->isPSample ) return; |
| 106756 | 106830 | assert( pOld->iCol>pNew->iCol ); |
| 106757 | 106831 | assert( sampleIsBetter(p, pNew, pOld) ); |
| 106758 | 106832 | if( pUpgrade==0 || sampleIsBetter(p, pOld, pUpgrade) ){ |
| | @@ -106767,11 +106841,11 @@ |
| 106767 | 106841 | } |
| 106768 | 106842 | } |
| 106769 | 106843 | |
| 106770 | 106844 | /* If necessary, remove sample iMin to make room for the new sample. */ |
| 106771 | 106845 | if( p->nSample>=p->mxSample ){ |
| 106772 | | - Stat4Sample *pMin = &p->a[p->iMin]; |
| 106846 | + StatSample *pMin = &p->a[p->iMin]; |
| 106773 | 106847 | tRowcnt *anEq = pMin->anEq; |
| 106774 | 106848 | tRowcnt *anLt = pMin->anLt; |
| 106775 | 106849 | tRowcnt *anDLt = pMin->anDLt; |
| 106776 | 106850 | sampleClear(p->db, pMin); |
| 106777 | 106851 | memmove(pMin, &pMin[1], sizeof(p->a[0])*(p->nSample-p->iMin-1)); |
| | @@ -106810,24 +106884,24 @@ |
| 106810 | 106884 | p->iMin = iMin; |
| 106811 | 106885 | } |
| 106812 | 106886 | } |
| 106813 | 106887 | #endif /* SQLITE_ENABLE_STAT4 */ |
| 106814 | 106888 | |
| 106889 | +#ifdef SQLITE_ENABLE_STAT4 |
| 106815 | 106890 | /* |
| 106816 | 106891 | ** Field iChng of the index being scanned has changed. So at this point |
| 106817 | 106892 | ** p->current contains a sample that reflects the previous row of the |
| 106818 | 106893 | ** index. The value of anEq[iChng] and subsequent anEq[] elements are |
| 106819 | 106894 | ** correct at this point. |
| 106820 | 106895 | */ |
| 106821 | | -static void samplePushPrevious(Stat4Accum *p, int iChng){ |
| 106822 | | -#ifdef SQLITE_ENABLE_STAT4 |
| 106896 | +static void samplePushPrevious(StatAccum *p, int iChng){ |
| 106823 | 106897 | int i; |
| 106824 | 106898 | |
| 106825 | 106899 | /* Check if any samples from the aBest[] array should be pushed |
| 106826 | 106900 | ** into IndexSample.a[] at this point. */ |
| 106827 | 106901 | for(i=(p->nCol-2); i>=iChng; i--){ |
| 106828 | | - Stat4Sample *pBest = &p->aBest[i]; |
| 106902 | + StatSample *pBest = &p->aBest[i]; |
| 106829 | 106903 | pBest->anEq[i] = p->current.anEq[i]; |
| 106830 | 106904 | if( p->nSample<p->mxSample || sampleIsBetter(p, pBest, &p->a[p->iMin]) ){ |
| 106831 | 106905 | sampleInsert(p, pBest, i); |
| 106832 | 106906 | } |
| 106833 | 106907 | } |
| | @@ -106847,29 +106921,24 @@ |
| 106847 | 106921 | if( p->a[i].anEq[j]==0 ) p->a[i].anEq[j] = p->current.anEq[j]; |
| 106848 | 106922 | } |
| 106849 | 106923 | } |
| 106850 | 106924 | p->nMaxEqZero = iChng; |
| 106851 | 106925 | } |
| 106852 | | -#endif |
| 106853 | | - |
| 106854 | | -#ifndef SQLITE_ENABLE_STAT4 |
| 106855 | | - UNUSED_PARAMETER( p ); |
| 106856 | | - UNUSED_PARAMETER( iChng ); |
| 106857 | | -#endif |
| 106858 | 106926 | } |
| 106927 | +#endif /* SQLITE_ENABLE_STAT4 */ |
| 106859 | 106928 | |
| 106860 | 106929 | /* |
| 106861 | 106930 | ** Implementation of the stat_push SQL function: stat_push(P,C,R) |
| 106862 | 106931 | ** Arguments: |
| 106863 | 106932 | ** |
| 106864 | | -** P Pointer to the Stat4Accum object created by stat_init() |
| 106933 | +** P Pointer to the StatAccum object created by stat_init() |
| 106865 | 106934 | ** C Index of left-most column to differ from previous row |
| 106866 | 106935 | ** R Rowid for the current row. Might be a key record for |
| 106867 | 106936 | ** WITHOUT ROWID tables. |
| 106868 | 106937 | ** |
| 106869 | 106938 | ** This SQL function always returns NULL. It's purpose it to accumulate |
| 106870 | | -** statistical data and/or samples in the Stat4Accum object about the |
| 106939 | +** statistical data and/or samples in the StatAccum object about the |
| 106871 | 106940 | ** index being analyzed. The stat_get() SQL function will later be used to |
| 106872 | 106941 | ** extract relevant information for constructing the sqlite_statN tables. |
| 106873 | 106942 | ** |
| 106874 | 106943 | ** The R parameter is only used for STAT4 |
| 106875 | 106944 | */ |
| | @@ -106879,11 +106948,11 @@ |
| 106879 | 106948 | sqlite3_value **argv |
| 106880 | 106949 | ){ |
| 106881 | 106950 | int i; |
| 106882 | 106951 | |
| 106883 | 106952 | /* The three function arguments */ |
| 106884 | | - Stat4Accum *p = (Stat4Accum*)sqlite3_value_blob(argv[0]); |
| 106953 | + StatAccum *p = (StatAccum*)sqlite3_value_blob(argv[0]); |
| 106885 | 106954 | int iChng = sqlite3_value_int(argv[1]); |
| 106886 | 106955 | |
| 106887 | 106956 | UNUSED_PARAMETER( argc ); |
| 106888 | 106957 | UNUSED_PARAMETER( context ); |
| 106889 | 106958 | assert( p->nCol>0 ); |
| | @@ -106892,11 +106961,13 @@ |
| 106892 | 106961 | if( p->nRow==0 ){ |
| 106893 | 106962 | /* This is the first call to this function. Do initialization. */ |
| 106894 | 106963 | for(i=0; i<p->nCol; i++) p->current.anEq[i] = 1; |
| 106895 | 106964 | }else{ |
| 106896 | 106965 | /* Second and subsequent calls get processed here */ |
| 106966 | +#ifdef SQLITE_ENABLE_STAT4 |
| 106897 | 106967 | samplePushPrevious(p, iChng); |
| 106968 | +#endif |
| 106898 | 106969 | |
| 106899 | 106970 | /* Update anDLt[], anLt[] and anEq[] to reflect the values that apply |
| 106900 | 106971 | ** to the current row of the index. */ |
| 106901 | 106972 | for(i=0; i<iChng; i++){ |
| 106902 | 106973 | p->current.anEq[i]++; |
| | @@ -106961,19 +107032,19 @@ |
| 106961 | 107032 | #define STAT_GET_NDLT 4 /* "ndlt" column of stat[34] entry */ |
| 106962 | 107033 | |
| 106963 | 107034 | /* |
| 106964 | 107035 | ** Implementation of the stat_get(P,J) SQL function. This routine is |
| 106965 | 107036 | ** used to query statistical information that has been gathered into |
| 106966 | | -** the Stat4Accum object by prior calls to stat_push(). The P parameter |
| 106967 | | -** has type BLOB but it is really just a pointer to the Stat4Accum object. |
| 107037 | +** the StatAccum object by prior calls to stat_push(). The P parameter |
| 107038 | +** has type BLOB but it is really just a pointer to the StatAccum object. |
| 106968 | 107039 | ** The content to returned is determined by the parameter J |
| 106969 | 107040 | ** which is one of the STAT_GET_xxxx values defined above. |
| 106970 | 107041 | ** |
| 106971 | 107042 | ** The stat_get(P,J) function is not available to generic SQL. It is |
| 106972 | 107043 | ** inserted as part of a manually constructed bytecode program. (See |
| 106973 | 107044 | ** the callStatGet() routine below.) It is guaranteed that the P |
| 106974 | | -** parameter will always be a poiner to a Stat4Accum object, never a |
| 107045 | +** parameter will always be a pointer to a StatAccum object, never a |
| 106975 | 107046 | ** NULL. |
| 106976 | 107047 | ** |
| 106977 | 107048 | ** If STAT4 is not enabled, then J is always |
| 106978 | 107049 | ** STAT_GET_STAT1 and is hence omitted and this routine becomes |
| 106979 | 107050 | ** a one-parameter function, stat_get(P), that always returns the |
| | @@ -106982,11 +107053,11 @@ |
| 106982 | 107053 | static void statGet( |
| 106983 | 107054 | sqlite3_context *context, |
| 106984 | 107055 | int argc, |
| 106985 | 107056 | sqlite3_value **argv |
| 106986 | 107057 | ){ |
| 106987 | | - Stat4Accum *p = (Stat4Accum*)sqlite3_value_blob(argv[0]); |
| 107058 | + StatAccum *p = (StatAccum*)sqlite3_value_blob(argv[0]); |
| 106988 | 107059 | #ifdef SQLITE_ENABLE_STAT4 |
| 106989 | 107060 | /* STAT4 has a parameter on this routine. */ |
| 106990 | 107061 | int eCall = sqlite3_value_int(argv[1]); |
| 106991 | 107062 | assert( argc==2 ); |
| 106992 | 107063 | assert( eCall==STAT_GET_STAT1 || eCall==STAT_GET_NEQ |
| | @@ -107003,11 +107074,11 @@ |
| 107003 | 107074 | ** |
| 107004 | 107075 | ** The value is a string composed of a list of integers describing |
| 107005 | 107076 | ** the index. The first integer in the list is the total number of |
| 107006 | 107077 | ** entries in the index. There is one additional integer in the list |
| 107007 | 107078 | ** for each indexed column. This additional integer is an estimate of |
| 107008 | | - ** the number of rows matched by a stabbing query on the index using |
| 107079 | + ** the number of rows matched by a equality query on the index using |
| 107009 | 107080 | ** a key with the corresponding number of fields. In other words, |
| 107010 | 107081 | ** if the index is on columns (a,b) and the sqlite_stat1 value is |
| 107011 | 107082 | ** "100 10 2", then SQLite estimates that: |
| 107012 | 107083 | ** |
| 107013 | 107084 | ** * the index contains 100 rows, |
| | @@ -107046,11 +107117,11 @@ |
| 107046 | 107117 | if( p->iGet<0 ){ |
| 107047 | 107118 | samplePushPrevious(p, 0); |
| 107048 | 107119 | p->iGet = 0; |
| 107049 | 107120 | } |
| 107050 | 107121 | if( p->iGet<p->nSample ){ |
| 107051 | | - Stat4Sample *pS = p->a + p->iGet; |
| 107122 | + StatSample *pS = p->a + p->iGet; |
| 107052 | 107123 | if( pS->nRowid==0 ){ |
| 107053 | 107124 | sqlite3_result_int64(context, pS->u.iRowid); |
| 107054 | 107125 | }else{ |
| 107055 | 107126 | sqlite3_result_blob(context, pS->u.aRowid, pS->nRowid, |
| 107056 | 107127 | SQLITE_TRANSIENT); |
| | @@ -107137,11 +107208,11 @@ |
| 107137 | 107208 | int i; /* Loop counter */ |
| 107138 | 107209 | int jZeroRows = -1; /* Jump from here if number of rows is zero */ |
| 107139 | 107210 | int iDb; /* Index of database containing pTab */ |
| 107140 | 107211 | u8 needTableCnt = 1; /* True to count the table */ |
| 107141 | 107212 | int regNewRowid = iMem++; /* Rowid for the inserted record */ |
| 107142 | | - int regStat4 = iMem++; /* Register to hold Stat4Accum object */ |
| 107213 | + int regStat4 = iMem++; /* Register to hold StatAccum object */ |
| 107143 | 107214 | int regChng = iMem++; /* Index of changed index field */ |
| 107144 | 107215 | #ifdef SQLITE_ENABLE_STAT4 |
| 107145 | 107216 | int regRowid = iMem++; /* Rowid argument passed to stat_push() */ |
| 107146 | 107217 | #endif |
| 107147 | 107218 | int regTemp = iMem++; /* Temporary use register */ |
| | @@ -108105,10 +108176,21 @@ |
| 108105 | 108176 | pExpr->op = TK_STRING; |
| 108106 | 108177 | } |
| 108107 | 108178 | } |
| 108108 | 108179 | return rc; |
| 108109 | 108180 | } |
| 108181 | + |
| 108182 | +/* |
| 108183 | +** Return true if zName points to a name that may be used to refer to |
| 108184 | +** database iDb attached to handle db. |
| 108185 | +*/ |
| 108186 | +SQLITE_PRIVATE int sqlite3DbIsNamed(sqlite3 *db, int iDb, const char *zName){ |
| 108187 | + return ( |
| 108188 | + sqlite3StrICmp(db->aDb[iDb].zDbSName, zName)==0 |
| 108189 | + || (iDb==0 && sqlite3StrICmp("main", zName)==0) |
| 108190 | + ); |
| 108191 | +} |
| 108110 | 108192 | |
| 108111 | 108193 | /* |
| 108112 | 108194 | ** An SQL user-function registered to do the work of an ATTACH statement. The |
| 108113 | 108195 | ** three arguments to the function come directly from an attach statement: |
| 108114 | 108196 | ** |
| | @@ -108178,13 +108260,12 @@ |
| 108178 | 108260 | db->aLimit[SQLITE_LIMIT_ATTACHED] |
| 108179 | 108261 | ); |
| 108180 | 108262 | goto attach_error; |
| 108181 | 108263 | } |
| 108182 | 108264 | for(i=0; i<db->nDb; i++){ |
| 108183 | | - char *z = db->aDb[i].zDbSName; |
| 108184 | | - assert( z && zName ); |
| 108185 | | - if( sqlite3StrICmp(z, zName)==0 ){ |
| 108265 | + assert( zName ); |
| 108266 | + if( sqlite3DbIsNamed(db, i, zName) ){ |
| 108186 | 108267 | zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName); |
| 108187 | 108268 | goto attach_error; |
| 108188 | 108269 | } |
| 108189 | 108270 | } |
| 108190 | 108271 | |
| | @@ -108333,11 +108414,11 @@ |
| 108333 | 108414 | |
| 108334 | 108415 | if( zName==0 ) zName = ""; |
| 108335 | 108416 | for(i=0; i<db->nDb; i++){ |
| 108336 | 108417 | pDb = &db->aDb[i]; |
| 108337 | 108418 | if( pDb->pBt==0 ) continue; |
| 108338 | | - if( sqlite3StrICmp(pDb->zDbSName, zName)==0 ) break; |
| 108419 | + if( sqlite3DbIsNamed(db, i, zName) ) break; |
| 108339 | 108420 | } |
| 108340 | 108421 | |
| 108341 | 108422 | if( i>=db->nDb ){ |
| 108342 | 108423 | sqlite3_snprintf(sizeof(zErr),zErr, "no such database: %s", zName); |
| 108343 | 108424 | goto detach_error; |
| | @@ -108524,24 +108605,25 @@ |
| 108524 | 108605 | SQLITE_PRIVATE int sqlite3FixSrcList( |
| 108525 | 108606 | DbFixer *pFix, /* Context of the fixation */ |
| 108526 | 108607 | SrcList *pList /* The Source list to check and modify */ |
| 108527 | 108608 | ){ |
| 108528 | 108609 | int i; |
| 108529 | | - const char *zDb; |
| 108530 | 108610 | struct SrcList_item *pItem; |
| 108611 | + sqlite3 *db = pFix->pParse->db; |
| 108612 | + int iDb = sqlite3FindDbName(db, pFix->zDb); |
| 108531 | 108613 | |
| 108532 | 108614 | if( NEVER(pList==0) ) return 0; |
| 108533 | | - zDb = pFix->zDb; |
| 108615 | + |
| 108534 | 108616 | for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){ |
| 108535 | 108617 | if( pFix->bTemp==0 ){ |
| 108536 | | - if( pItem->zDatabase && sqlite3StrICmp(pItem->zDatabase, zDb) ){ |
| 108618 | + if( pItem->zDatabase && iDb!=sqlite3FindDbName(db, pItem->zDatabase) ){ |
| 108537 | 108619 | sqlite3ErrorMsg(pFix->pParse, |
| 108538 | 108620 | "%s %T cannot reference objects in database %s", |
| 108539 | 108621 | pFix->zType, pFix->pName, pItem->zDatabase); |
| 108540 | 108622 | return 1; |
| 108541 | 108623 | } |
| 108542 | | - sqlite3DbFree(pFix->pParse->db, pItem->zDatabase); |
| 108624 | + sqlite3DbFree(db, pItem->zDatabase); |
| 108543 | 108625 | pItem->zDatabase = 0; |
| 108544 | 108626 | pItem->pSchema = pFix->pSchema; |
| 108545 | 108627 | pItem->fg.fromDDL = 1; |
| 108546 | 108628 | } |
| 108547 | 108629 | #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER) |
| | @@ -109262,11 +109344,11 @@ |
| 109262 | 109344 | } |
| 109263 | 109345 | #endif |
| 109264 | 109346 | while(1){ |
| 109265 | 109347 | for(i=OMIT_TEMPDB; i<db->nDb; i++){ |
| 109266 | 109348 | int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ |
| 109267 | | - if( zDatabase==0 || sqlite3StrICmp(zDatabase, db->aDb[j].zDbSName)==0 ){ |
| 109349 | + if( zDatabase==0 || sqlite3DbIsNamed(db, j, zDatabase) ){ |
| 109268 | 109350 | assert( sqlite3SchemaMutexHeld(db, j, 0) ); |
| 109269 | 109351 | p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName); |
| 109270 | 109352 | if( p ) return p; |
| 109271 | 109353 | } |
| 109272 | 109354 | } |
| | @@ -109384,11 +109466,11 @@ |
| 109384 | 109466 | assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) ); |
| 109385 | 109467 | for(i=OMIT_TEMPDB; i<db->nDb; i++){ |
| 109386 | 109468 | int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ |
| 109387 | 109469 | Schema *pSchema = db->aDb[j].pSchema; |
| 109388 | 109470 | assert( pSchema ); |
| 109389 | | - if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zDbSName) ) continue; |
| 109471 | + if( zDb && sqlite3DbIsNamed(db, j, zDb)==0 ) continue; |
| 109390 | 109472 | assert( sqlite3SchemaMutexHeld(db, j, 0) ); |
| 109391 | 109473 | p = sqlite3HashFind(&pSchema->idxHash, zName); |
| 109392 | 109474 | if( p ) break; |
| 109393 | 109475 | } |
| 109394 | 109476 | return p; |
| | @@ -111103,10 +111185,36 @@ |
| 111103 | 111185 | if( pMod->pModule->iVersion<3 ) return 0; |
| 111104 | 111186 | if( pMod->pModule->xShadowName==0 ) return 0; |
| 111105 | 111187 | return pMod->pModule->xShadowName(zTail+1); |
| 111106 | 111188 | } |
| 111107 | 111189 | #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */ |
| 111190 | + |
| 111191 | +#ifdef SQLITE_DEBUG |
| 111192 | +/* |
| 111193 | +** Mark all nodes of an expression as EP_Immutable, indicating that |
| 111194 | +** they should not be changed. Expressions attached to a table or |
| 111195 | +** index definition are tagged this way to help ensure that we do |
| 111196 | +** not pass them into code generator routines by mistake. |
| 111197 | +*/ |
| 111198 | +static int markImmutableExprStep(Walker *pWalker, Expr *pExpr){ |
| 111199 | + ExprSetVVAProperty(pExpr, EP_Immutable); |
| 111200 | + return WRC_Continue; |
| 111201 | +} |
| 111202 | +static void markExprListImmutable(ExprList *pList){ |
| 111203 | + if( pList ){ |
| 111204 | + Walker w; |
| 111205 | + memset(&w, 0, sizeof(w)); |
| 111206 | + w.xExprCallback = markImmutableExprStep; |
| 111207 | + w.xSelectCallback = sqlite3SelectWalkNoop; |
| 111208 | + w.xSelectCallback2 = 0; |
| 111209 | + sqlite3WalkExprList(&w, pList); |
| 111210 | + } |
| 111211 | +} |
| 111212 | +#else |
| 111213 | +#define markExprListImmutable(X) /* no-op */ |
| 111214 | +#endif /* SQLITE_DEBUG */ |
| 111215 | + |
| 111108 | 111216 | |
| 111109 | 111217 | /* |
| 111110 | 111218 | ** This routine is called to report the final ")" that terminates |
| 111111 | 111219 | ** a CREATE TABLE statement. |
| 111112 | 111220 | ** |
| | @@ -111196,10 +111304,12 @@ |
| 111196 | 111304 | if( pParse->nErr ){ |
| 111197 | 111305 | /* If errors are seen, delete the CHECK constraints now, else they might |
| 111198 | 111306 | ** actually be used if PRAGMA writable_schema=ON is set. */ |
| 111199 | 111307 | sqlite3ExprListDelete(db, p->pCheck); |
| 111200 | 111308 | p->pCheck = 0; |
| 111309 | + }else{ |
| 111310 | + markExprListImmutable(p->pCheck); |
| 111201 | 111311 | } |
| 111202 | 111312 | } |
| 111203 | 111313 | #endif /* !defined(SQLITE_OMIT_CHECK) */ |
| 111204 | 111314 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 111205 | 111315 | if( p->tabFlags & TF_HasGenerated ){ |
| | @@ -114137,20 +114247,33 @@ |
| 114137 | 114247 | u8 enc, /* Desired text encoding */ |
| 114138 | 114248 | const char *zName, /* Name of the collating sequence. Might be NULL */ |
| 114139 | 114249 | int create /* True to create CollSeq if doesn't already exist */ |
| 114140 | 114250 | ){ |
| 114141 | 114251 | CollSeq *pColl; |
| 114252 | + assert( SQLITE_UTF8==1 && SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 ); |
| 114253 | + assert( enc>=SQLITE_UTF8 && enc<=SQLITE_UTF16BE ); |
| 114142 | 114254 | if( zName ){ |
| 114143 | 114255 | pColl = findCollSeqEntry(db, zName, create); |
| 114256 | + if( pColl ) pColl += enc-1; |
| 114144 | 114257 | }else{ |
| 114145 | 114258 | pColl = db->pDfltColl; |
| 114146 | 114259 | } |
| 114147 | | - assert( SQLITE_UTF8==1 && SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 ); |
| 114148 | | - assert( enc>=SQLITE_UTF8 && enc<=SQLITE_UTF16BE ); |
| 114149 | | - if( pColl ) pColl += enc-1; |
| 114150 | 114260 | return pColl; |
| 114151 | 114261 | } |
| 114262 | + |
| 114263 | +/* |
| 114264 | +** Change the text encoding for a database connection. This means that |
| 114265 | +** the pDfltColl must change as well. |
| 114266 | +*/ |
| 114267 | +SQLITE_PRIVATE void sqlite3SetTextEncoding(sqlite3 *db, u8 enc){ |
| 114268 | + assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE ); |
| 114269 | + db->enc = enc; |
| 114270 | + /* EVIDENCE-OF: R-08308-17224 The default collating function for all |
| 114271 | + ** strings is BINARY. |
| 114272 | + */ |
| 114273 | + db->pDfltColl = sqlite3FindCollSeq(db, enc, sqlite3StrBINARY, 0); |
| 114274 | +} |
| 114152 | 114275 | |
| 114153 | 114276 | /* |
| 114154 | 114277 | ** This function is responsible for invoking the collation factory callback |
| 114155 | 114278 | ** or substituting a collation sequence of a different encoding when the |
| 114156 | 114279 | ** requested collation sequence is not available in the desired encoding. |
| | @@ -116321,10 +116444,11 @@ |
| 116321 | 116444 | const unsigned char *zA, *zB; |
| 116322 | 116445 | u32 escape; |
| 116323 | 116446 | int nPat; |
| 116324 | 116447 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 116325 | 116448 | struct compareInfo *pInfo = sqlite3_user_data(context); |
| 116449 | + struct compareInfo backupInfo; |
| 116326 | 116450 | |
| 116327 | 116451 | #ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS |
| 116328 | 116452 | if( sqlite3_value_type(argv[0])==SQLITE_BLOB |
| 116329 | 116453 | || sqlite3_value_type(argv[1])==SQLITE_BLOB |
| 116330 | 116454 | ){ |
| | @@ -116356,10 +116480,16 @@ |
| 116356 | 116480 | sqlite3_result_error(context, |
| 116357 | 116481 | "ESCAPE expression must be a single character", -1); |
| 116358 | 116482 | return; |
| 116359 | 116483 | } |
| 116360 | 116484 | escape = sqlite3Utf8Read(&zEsc); |
| 116485 | + if( escape==pInfo->matchAll || escape==pInfo->matchOne ){ |
| 116486 | + memcpy(&backupInfo, pInfo, sizeof(backupInfo)); |
| 116487 | + pInfo = &backupInfo; |
| 116488 | + if( escape==pInfo->matchAll ) pInfo->matchAll = 0; |
| 116489 | + if( escape==pInfo->matchOne ) pInfo->matchOne = 0; |
| 116490 | + } |
| 116361 | 116491 | }else{ |
| 116362 | 116492 | escape = pInfo->matchSet; |
| 116363 | 116493 | } |
| 116364 | 116494 | zB = sqlite3_value_text(argv[0]); |
| 116365 | 116495 | zA = sqlite3_value_text(argv[1]); |
| | @@ -117338,29 +117468,33 @@ |
| 117338 | 117468 | if( pDef==0 ) return 0; |
| 117339 | 117469 | #endif |
| 117340 | 117470 | if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){ |
| 117341 | 117471 | return 0; |
| 117342 | 117472 | } |
| 117343 | | - if( nExpr<3 ){ |
| 117344 | | - aWc[3] = 0; |
| 117345 | | - }else{ |
| 117346 | | - Expr *pEscape = pExpr->x.pList->a[2].pExpr; |
| 117347 | | - char *zEscape; |
| 117348 | | - if( pEscape->op!=TK_STRING ) return 0; |
| 117349 | | - zEscape = pEscape->u.zToken; |
| 117350 | | - if( zEscape[0]==0 || zEscape[1]!=0 ) return 0; |
| 117351 | | - aWc[3] = zEscape[0]; |
| 117352 | | - } |
| 117353 | 117473 | |
| 117354 | 117474 | /* The memcpy() statement assumes that the wildcard characters are |
| 117355 | 117475 | ** the first three statements in the compareInfo structure. The |
| 117356 | 117476 | ** asserts() that follow verify that assumption |
| 117357 | 117477 | */ |
| 117358 | 117478 | memcpy(aWc, pDef->pUserData, 3); |
| 117359 | 117479 | assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll ); |
| 117360 | 117480 | assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne ); |
| 117361 | 117481 | assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet ); |
| 117482 | + |
| 117483 | + if( nExpr<3 ){ |
| 117484 | + aWc[3] = 0; |
| 117485 | + }else{ |
| 117486 | + Expr *pEscape = pExpr->x.pList->a[2].pExpr; |
| 117487 | + char *zEscape; |
| 117488 | + if( pEscape->op!=TK_STRING ) return 0; |
| 117489 | + zEscape = pEscape->u.zToken; |
| 117490 | + if( zEscape[0]==0 || zEscape[1]!=0 ) return 0; |
| 117491 | + if( zEscape[0]==aWc[0] ) return 0; |
| 117492 | + if( zEscape[0]==aWc[1] ) return 0; |
| 117493 | + aWc[3] = zEscape[0]; |
| 117494 | + } |
| 117495 | + |
| 117362 | 117496 | *pIsNocase = (pDef->funcFlags & SQLITE_FUNC_CASE)==0; |
| 117363 | 117497 | return 1; |
| 117364 | 117498 | } |
| 117365 | 117499 | |
| 117366 | 117500 | /* |
| | @@ -120564,11 +120698,11 @@ |
| 120564 | 120698 | case OE_Replace: { |
| 120565 | 120699 | int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, iReg); |
| 120566 | 120700 | VdbeCoverage(v); |
| 120567 | 120701 | assert( (pCol->colFlags & COLFLAG_GENERATED)==0 ); |
| 120568 | 120702 | nSeenReplace++; |
| 120569 | | - sqlite3ExprCode(pParse, pCol->pDflt, iReg); |
| 120703 | + sqlite3ExprCodeCopy(pParse, pCol->pDflt, iReg); |
| 120570 | 120704 | sqlite3VdbeJumpHere(v, addr1); |
| 120571 | 120705 | break; |
| 120572 | 120706 | } |
| 120573 | 120707 | case OE_Abort: |
| 120574 | 120708 | sqlite3MayAbort(pParse); |
| | @@ -120619,10 +120753,11 @@ |
| 120619 | 120753 | ExprList *pCheck = pTab->pCheck; |
| 120620 | 120754 | pParse->iSelfTab = -(regNewData+1); |
| 120621 | 120755 | onError = overrideError!=OE_Default ? overrideError : OE_Abort; |
| 120622 | 120756 | for(i=0; i<pCheck->nExpr; i++){ |
| 120623 | 120757 | int allOk; |
| 120758 | + Expr *pCopy; |
| 120624 | 120759 | Expr *pExpr = pCheck->a[i].pExpr; |
| 120625 | 120760 | if( aiChng |
| 120626 | 120761 | && !sqlite3ExprReferencesUpdatedColumn(pExpr, aiChng, pkChng) |
| 120627 | 120762 | ){ |
| 120628 | 120763 | /* The check constraints do not reference any of the columns being |
| | @@ -120633,11 +120768,15 @@ |
| 120633 | 120768 | sqlite3TableAffinity(v, pTab, regNewData+1); |
| 120634 | 120769 | bAffinityDone = 1; |
| 120635 | 120770 | } |
| 120636 | 120771 | allOk = sqlite3VdbeMakeLabel(pParse); |
| 120637 | 120772 | sqlite3VdbeVerifyAbortable(v, onError); |
| 120638 | | - sqlite3ExprIfTrue(pParse, pExpr, allOk, SQLITE_JUMPIFNULL); |
| 120773 | + pCopy = sqlite3ExprDup(db, pExpr, 0); |
| 120774 | + if( !db->mallocFailed ){ |
| 120775 | + sqlite3ExprIfTrue(pParse, pCopy, allOk, SQLITE_JUMPIFNULL); |
| 120776 | + } |
| 120777 | + sqlite3ExprDelete(db, pCopy); |
| 120639 | 120778 | if( onError==OE_Ignore ){ |
| 120640 | 120779 | sqlite3VdbeGoto(v, ignoreDest); |
| 120641 | 120780 | }else{ |
| 120642 | 120781 | char *zName = pCheck->a[i].zEName; |
| 120643 | 120782 | if( zName==0 ) zName = pTab->zName; |
| | @@ -125952,25 +126091,16 @@ |
| 125952 | 126091 | /* Only change the value of sqlite.enc if the database handle is not |
| 125953 | 126092 | ** initialized. If the main database exists, the new sqlite.enc value |
| 125954 | 126093 | ** will be overwritten when the schema is next loaded. If it does not |
| 125955 | 126094 | ** already exists, it will be created to use the new encoding value. |
| 125956 | 126095 | */ |
| 125957 | | - int canChangeEnc = 1; /* True if allowed to change the encoding */ |
| 125958 | | - int i; /* For looping over all attached databases */ |
| 125959 | | - for(i=0; i<db->nDb; i++){ |
| 125960 | | - if( db->aDb[i].pBt!=0 |
| 125961 | | - && DbHasProperty(db,i,DB_SchemaLoaded) |
| 125962 | | - && !DbHasProperty(db,i,DB_Empty) |
| 125963 | | - ){ |
| 125964 | | - canChangeEnc = 0; |
| 125965 | | - } |
| 125966 | | - } |
| 125967 | | - if( canChangeEnc ){ |
| 126096 | + if( (db->mDbFlags & DBFLAG_EncodingFixed)==0 ){ |
| 125968 | 126097 | for(pEnc=&encnames[0]; pEnc->zName; pEnc++){ |
| 125969 | 126098 | if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){ |
| 125970 | | - SCHEMA_ENC(db) = ENC(db) = |
| 125971 | | - pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE; |
| 126099 | + u8 enc = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE; |
| 126100 | + SCHEMA_ENC(db) = enc; |
| 126101 | + sqlite3SetTextEncoding(db, enc); |
| 125972 | 126102 | break; |
| 125973 | 126103 | } |
| 125974 | 126104 | } |
| 125975 | 126105 | if( !pEnc->zName ){ |
| 125976 | 126106 | sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight); |
| | @@ -126775,11 +126905,11 @@ |
| 126775 | 126905 | int iDb = pData->iDb; |
| 126776 | 126906 | |
| 126777 | 126907 | assert( argc==5 ); |
| 126778 | 126908 | UNUSED_PARAMETER2(NotUsed, argc); |
| 126779 | 126909 | assert( sqlite3_mutex_held(db->mutex) ); |
| 126780 | | - DbClearProperty(db, iDb, DB_Empty); |
| 126910 | + db->mDbFlags |= DBFLAG_EncodingFixed; |
| 126781 | 126911 | pData->nInitRow++; |
| 126782 | 126912 | if( db->mallocFailed ){ |
| 126783 | 126913 | corruptSchema(pData, argv[1], 0); |
| 126784 | 126914 | return 1; |
| 126785 | 126915 | } |
| | @@ -126863,10 +126993,11 @@ |
| 126863 | 126993 | char const *azArg[6]; |
| 126864 | 126994 | int meta[5]; |
| 126865 | 126995 | InitData initData; |
| 126866 | 126996 | const char *zMasterName; |
| 126867 | 126997 | int openedTransaction = 0; |
| 126998 | + int mask = ((db->mDbFlags & DBFLAG_EncodingFixed) | ~DBFLAG_EncodingFixed); |
| 126868 | 126999 | |
| 126869 | 127000 | assert( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0 ); |
| 126870 | 127001 | assert( iDb>=0 && iDb<db->nDb ); |
| 126871 | 127002 | assert( db->aDb[iDb].pSchema ); |
| 126872 | 127003 | assert( sqlite3_mutex_held(db->mutex) ); |
| | @@ -126891,10 +127022,11 @@ |
| 126891 | 127022 | initData.rc = SQLITE_OK; |
| 126892 | 127023 | initData.pzErrMsg = pzErrMsg; |
| 126893 | 127024 | initData.mInitFlags = mFlags; |
| 126894 | 127025 | initData.nInitRow = 0; |
| 126895 | 127026 | sqlite3InitCallback(&initData, 5, (char **)azArg, 0); |
| 127027 | + db->mDbFlags &= mask; |
| 126896 | 127028 | if( initData.rc ){ |
| 126897 | 127029 | rc = initData.rc; |
| 126898 | 127030 | goto error_out; |
| 126899 | 127031 | } |
| 126900 | 127032 | |
| | @@ -126950,31 +127082,29 @@ |
| 126950 | 127082 | ** main database, set sqlite3.enc to the encoding of the main database. |
| 126951 | 127083 | ** For an attached db, it is an error if the encoding is not the same |
| 126952 | 127084 | ** as sqlite3.enc. |
| 126953 | 127085 | */ |
| 126954 | 127086 | if( meta[BTREE_TEXT_ENCODING-1] ){ /* text encoding */ |
| 126955 | | - if( iDb==0 ){ |
| 126956 | | -#ifndef SQLITE_OMIT_UTF16 |
| 127087 | + if( iDb==0 && (db->mDbFlags & DBFLAG_EncodingFixed)==0 ){ |
| 126957 | 127088 | u8 encoding; |
| 127089 | +#ifndef SQLITE_OMIT_UTF16 |
| 126958 | 127090 | /* If opening the main database, set ENC(db). */ |
| 126959 | 127091 | encoding = (u8)meta[BTREE_TEXT_ENCODING-1] & 3; |
| 126960 | 127092 | if( encoding==0 ) encoding = SQLITE_UTF8; |
| 126961 | | - ENC(db) = encoding; |
| 126962 | 127093 | #else |
| 126963 | | - ENC(db) = SQLITE_UTF8; |
| 127094 | + encoding = SQLITE_UTF8; |
| 126964 | 127095 | #endif |
| 127096 | + sqlite3SetTextEncoding(db, encoding); |
| 126965 | 127097 | }else{ |
| 126966 | 127098 | /* If opening an attached database, the encoding much match ENC(db) */ |
| 126967 | | - if( meta[BTREE_TEXT_ENCODING-1]!=ENC(db) ){ |
| 127099 | + if( (meta[BTREE_TEXT_ENCODING-1] & 3)!=ENC(db) ){ |
| 126968 | 127100 | sqlite3SetString(pzErrMsg, db, "attached databases must use the same" |
| 126969 | 127101 | " text encoding as main database"); |
| 126970 | 127102 | rc = SQLITE_ERROR; |
| 126971 | 127103 | goto initone_error_out; |
| 126972 | 127104 | } |
| 126973 | 127105 | } |
| 126974 | | - }else{ |
| 126975 | | - DbSetProperty(db, iDb, DB_Empty); |
| 126976 | 127106 | } |
| 126977 | 127107 | pDb->pSchema->enc = ENC(db); |
| 126978 | 127108 | |
| 126979 | 127109 | if( pDb->pSchema->cache_size==0 ){ |
| 126980 | 127110 | #ifndef SQLITE_OMIT_DEPRECATED |
| | @@ -127082,12 +127212,11 @@ |
| 127082 | 127212 | ** used to store temporary tables, and any additional database files |
| 127083 | 127213 | ** created using ATTACH statements. Return a success code. If an |
| 127084 | 127214 | ** error occurs, write an error message into *pzErrMsg. |
| 127085 | 127215 | ** |
| 127086 | 127216 | ** After a database is initialized, the DB_SchemaLoaded bit is set |
| 127087 | | -** bit is set in the flags field of the Db structure. If the database |
| 127088 | | -** file was of zero-length, then the DB_Empty flag is also set. |
| 127217 | +** bit is set in the flags field of the Db structure. |
| 127089 | 127218 | */ |
| 127090 | 127219 | SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){ |
| 127091 | 127220 | int i, rc; |
| 127092 | 127221 | int commit_internal = !(db->mDbFlags&DBFLAG_SchemaChange); |
| 127093 | 127222 | |
| | @@ -127719,11 +127848,10 @@ |
| 127719 | 127848 | sqlite3ExprDelete(db, p->pLimit); |
| 127720 | 127849 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 127721 | 127850 | if( OK_IF_ALWAYS_TRUE(p->pWinDefn) ){ |
| 127722 | 127851 | sqlite3WindowListDelete(db, p->pWinDefn); |
| 127723 | 127852 | } |
| 127724 | | - assert( p->pWin==0 ); |
| 127725 | 127853 | #endif |
| 127726 | 127854 | if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith); |
| 127727 | 127855 | if( bFree ) sqlite3DbFreeNN(db, p); |
| 127728 | 127856 | p = pPrior; |
| 127729 | 127857 | bFree = 1; |
| | @@ -131197,10 +131325,42 @@ |
| 131197 | 131325 | } |
| 131198 | 131326 | }while( doPrior && (p = p->pPrior)!=0 ); |
| 131199 | 131327 | } |
| 131200 | 131328 | #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */ |
| 131201 | 131329 | |
| 131330 | +#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 131331 | +/* |
| 131332 | +** pSelect is a SELECT statement and pSrcItem is one item in the FROM |
| 131333 | +** clause of that SELECT. |
| 131334 | +** |
| 131335 | +** This routine scans the entire SELECT statement and recomputes the |
| 131336 | +** pSrcItem->colUsed mask. |
| 131337 | +*/ |
| 131338 | +static int recomputeColumnsUsedExpr(Walker *pWalker, Expr *pExpr){ |
| 131339 | + struct SrcList_item *pItem; |
| 131340 | + if( pExpr->op!=TK_COLUMN ) return WRC_Continue; |
| 131341 | + pItem = pWalker->u.pSrcItem; |
| 131342 | + if( pItem->iCursor!=pExpr->iTable ) return WRC_Continue; |
| 131343 | + if( pExpr->iColumn<0 ) return WRC_Continue; |
| 131344 | + pItem->colUsed |= sqlite3ExprColUsed(pExpr); |
| 131345 | + return WRC_Continue; |
| 131346 | +} |
| 131347 | +static void recomputeColumnsUsed( |
| 131348 | + Select *pSelect, /* The complete SELECT statement */ |
| 131349 | + struct SrcList_item *pSrcItem /* Which FROM clause item to recompute */ |
| 131350 | +){ |
| 131351 | + Walker w; |
| 131352 | + if( NEVER(pSrcItem->pTab==0) ) return; |
| 131353 | + memset(&w, 0, sizeof(w)); |
| 131354 | + w.xExprCallback = recomputeColumnsUsedExpr; |
| 131355 | + w.xSelectCallback = sqlite3SelectWalkNoop; |
| 131356 | + w.u.pSrcItem = pSrcItem; |
| 131357 | + pSrcItem->colUsed = 0; |
| 131358 | + sqlite3WalkSelect(&w, pSelect); |
| 131359 | +} |
| 131360 | +#endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */ |
| 131361 | + |
| 131202 | 131362 | #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 131203 | 131363 | /* |
| 131204 | 131364 | ** This routine attempts to flatten subqueries as a performance optimization. |
| 131205 | 131365 | ** This routine returns 1 if it makes changes and 0 if no flattening occurs. |
| 131206 | 131366 | ** |
| | @@ -131735,10 +131895,16 @@ |
| 131735 | 131895 | */ |
| 131736 | 131896 | if( pSub->pLimit ){ |
| 131737 | 131897 | pParent->pLimit = pSub->pLimit; |
| 131738 | 131898 | pSub->pLimit = 0; |
| 131739 | 131899 | } |
| 131900 | + |
| 131901 | + /* Recompute the SrcList_item.colUsed masks for the flattened |
| 131902 | + ** tables. */ |
| 131903 | + for(i=0; i<nSubSrc; i++){ |
| 131904 | + recomputeColumnsUsed(pParent, &pSrc->a[i+iFrom]); |
| 131905 | + } |
| 131740 | 131906 | } |
| 131741 | 131907 | |
| 131742 | 131908 | /* Finially, delete what is left of the subquery and return |
| 131743 | 131909 | ** success. |
| 131744 | 131910 | */ |
| | @@ -135184,11 +135350,11 @@ |
| 135184 | 135350 | zDb = pName->a[0].zDatabase; |
| 135185 | 135351 | zName = pName->a[0].zName; |
| 135186 | 135352 | assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) ); |
| 135187 | 135353 | for(i=OMIT_TEMPDB; i<db->nDb; i++){ |
| 135188 | 135354 | int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ |
| 135189 | | - if( zDb && sqlite3StrICmp(db->aDb[j].zDbSName, zDb) ) continue; |
| 135355 | + if( zDb && sqlite3DbIsNamed(db, j, zDb)==0 ) continue; |
| 135190 | 135356 | assert( sqlite3SchemaMutexHeld(db, j, 0) ); |
| 135191 | 135357 | pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName); |
| 135192 | 135358 | if( pTrigger ) break; |
| 135193 | 135359 | } |
| 135194 | 135360 | if( !pTrigger ){ |
| | @@ -141206,10 +141372,13 @@ |
| 141206 | 141372 | assert( pRangeEnd==0 && pRangeStart==0 ); |
| 141207 | 141373 | testcase( pLoop->nSkip>0 ); |
| 141208 | 141374 | nExtraReg = 1; |
| 141209 | 141375 | bSeekPastNull = 1; |
| 141210 | 141376 | pLevel->regBignull = regBignull = ++pParse->nMem; |
| 141377 | + if( pLevel->iLeftJoin ){ |
| 141378 | + sqlite3VdbeAddOp2(v, OP_Integer, 0, regBignull); |
| 141379 | + } |
| 141211 | 141380 | pLevel->addrBignull = sqlite3VdbeMakeLabel(pParse); |
| 141212 | 141381 | } |
| 141213 | 141382 | |
| 141214 | 141383 | /* If we are doing a reverse order scan on an ascending index, or |
| 141215 | 141384 | ** a forward order scan on a descending index, interchange the |
| | @@ -148759,11 +148928,11 @@ |
| 148759 | 148928 | && (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0 |
| 148760 | 148929 | && (pLoop->wsFlags & WHERE_BIGNULL_SORT)==0 |
| 148761 | 148930 | && (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0 |
| 148762 | 148931 | && pWInfo->eDistinct!=WHERE_DISTINCT_ORDERED |
| 148763 | 148932 | ){ |
| 148764 | | - sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ); /* Hint to COMDB2 */ |
| 148933 | + sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ); |
| 148765 | 148934 | } |
| 148766 | 148935 | VdbeComment((v, "%s", pIx->zName)); |
| 148767 | 148936 | #ifdef SQLITE_ENABLE_COLUMN_USED_MASK |
| 148768 | 148937 | { |
| 148769 | 148938 | u64 colUsed = 0; |
| | @@ -148917,16 +149086,10 @@ |
| 148917 | 149086 | for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){ |
| 148918 | 149087 | sqlite3VdbeJumpHere(v, pIn->addrInTop+1); |
| 148919 | 149088 | if( pIn->eEndLoopOp!=OP_Noop ){ |
| 148920 | 149089 | if( pIn->nPrefix ){ |
| 148921 | 149090 | assert( pLoop->wsFlags & WHERE_IN_EARLYOUT ); |
| 148922 | | - if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 ){ |
| 148923 | | - sqlite3VdbeAddOp4Int(v, OP_IfNoHope, pLevel->iIdxCur, |
| 148924 | | - sqlite3VdbeCurrentAddr(v)+2+(pLevel->iLeftJoin!=0), |
| 148925 | | - pIn->iBase, pIn->nPrefix); |
| 148926 | | - VdbeCoverage(v); |
| 148927 | | - } |
| 148928 | 149091 | if( pLevel->iLeftJoin ){ |
| 148929 | 149092 | /* For LEFT JOIN queries, cursor pIn->iCur may not have been |
| 148930 | 149093 | ** opened yet. This occurs for WHERE clauses such as |
| 148931 | 149094 | ** "a = ? AND b IN (...)", where the index is on (a, b). If |
| 148932 | 149095 | ** the RHS of the (a=?) is NULL, then the "b IN (...)" may |
| | @@ -148933,13 +149096,20 @@ |
| 148933 | 149096 | ** never have been coded, but the body of the loop run to |
| 148934 | 149097 | ** return the null-row. So, if the cursor is not open yet, |
| 148935 | 149098 | ** jump over the OP_Next or OP_Prev instruction about to |
| 148936 | 149099 | ** be coded. */ |
| 148937 | 149100 | sqlite3VdbeAddOp2(v, OP_IfNotOpen, pIn->iCur, |
| 148938 | | - sqlite3VdbeCurrentAddr(v) + 2 |
| 149101 | + sqlite3VdbeCurrentAddr(v) + 2 + |
| 149102 | + ((pLoop->wsFlags & WHERE_VIRTUALTABLE)==0) |
| 148939 | 149103 | ); |
| 148940 | 149104 | VdbeCoverage(v); |
| 149105 | + } |
| 149106 | + if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 ){ |
| 149107 | + sqlite3VdbeAddOp4Int(v, OP_IfNoHope, pLevel->iIdxCur, |
| 149108 | + sqlite3VdbeCurrentAddr(v)+2, |
| 149109 | + pIn->iBase, pIn->nPrefix); |
| 149110 | + VdbeCoverage(v); |
| 148941 | 149111 | } |
| 148942 | 149112 | } |
| 148943 | 149113 | sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop); |
| 148944 | 149114 | VdbeCoverage(v); |
| 148945 | 149115 | VdbeCoverageIf(v, pIn->eEndLoopOp==OP_Prev); |
| | @@ -150053,10 +150223,11 @@ |
| 150053 | 150223 | |
| 150054 | 150224 | ExprList *pSublist = 0; /* Expression list for sub-query */ |
| 150055 | 150225 | Window *pMWin = p->pWin; /* Master window object */ |
| 150056 | 150226 | Window *pWin; /* Window object iterator */ |
| 150057 | 150227 | Table *pTab; |
| 150228 | + u32 selFlags = p->selFlags; |
| 150058 | 150229 | |
| 150059 | 150230 | pTab = sqlite3DbMallocZero(db, sizeof(Table)); |
| 150060 | 150231 | if( pTab==0 ){ |
| 150061 | 150232 | return sqlite3ErrorToParser(db, SQLITE_NOMEM); |
| 150062 | 150233 | } |
| | @@ -150142,10 +150313,11 @@ |
| 150142 | 150313 | Table *pTab2; |
| 150143 | 150314 | p->pSrc->a[0].pSelect = pSub; |
| 150144 | 150315 | sqlite3SrcListAssignCursors(pParse, p->pSrc); |
| 150145 | 150316 | pSub->selFlags |= SF_Expanded; |
| 150146 | 150317 | pTab2 = sqlite3ResultSetOfSelect(pParse, pSub, SQLITE_AFF_NONE); |
| 150318 | + pSub->selFlags |= (selFlags & SF_Aggregate); |
| 150147 | 150319 | if( pTab2==0 ){ |
| 150148 | 150320 | /* Might actually be some other kind of error, but in that case |
| 150149 | 150321 | ** pParse->nErr will be set, so if SQLITE_NOMEM is set, we will get |
| 150150 | 150322 | ** the correct error message regardless. */ |
| 150151 | 150323 | rc = SQLITE_NOMEM; |
| | @@ -151030,10 +151202,11 @@ |
| 151030 | 151202 | int regArg; |
| 151031 | 151203 | int nArg = 0; |
| 151032 | 151204 | Window *pWin; |
| 151033 | 151205 | for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ |
| 151034 | 151206 | FuncDef *pFunc = pWin->pFunc; |
| 151207 | + assert( pWin->regAccum ); |
| 151035 | 151208 | sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum); |
| 151036 | 151209 | nArg = MAX(nArg, windowArgCount(pWin)); |
| 151037 | 151210 | if( pMWin->regStartRowid==0 ){ |
| 151038 | 151211 | if( pFunc->zName==nth_valueName || pFunc->zName==first_valueName ){ |
| 151039 | 151212 | sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp); |
| | @@ -151408,10 +151581,14 @@ |
| 151408 | 151581 | pNew->eFrmType = p->eFrmType; |
| 151409 | 151582 | pNew->eEnd = p->eEnd; |
| 151410 | 151583 | pNew->eStart = p->eStart; |
| 151411 | 151584 | pNew->eExclude = p->eExclude; |
| 151412 | 151585 | pNew->regResult = p->regResult; |
| 151586 | + pNew->regAccum = p->regAccum; |
| 151587 | + pNew->iArgCol = p->iArgCol; |
| 151588 | + pNew->iEphCsr = p->iEphCsr; |
| 151589 | + pNew->bExprArgs = p->bExprArgs; |
| 151413 | 151590 | pNew->pStart = sqlite3ExprDup(db, p->pStart, 0); |
| 151414 | 151591 | pNew->pEnd = sqlite3ExprDup(db, p->pEnd, 0); |
| 151415 | 151592 | pNew->pOwner = pOwner; |
| 151416 | 151593 | pNew->bImplicitFrame = p->bImplicitFrame; |
| 151417 | 151594 | } |
| | @@ -152245,10 +152422,11 @@ |
| 152245 | 152422 | if( p ){ |
| 152246 | 152423 | /* memset(p, 0, sizeof(Expr)); */ |
| 152247 | 152424 | p->op = (u8)op; |
| 152248 | 152425 | p->affExpr = 0; |
| 152249 | 152426 | p->flags = EP_Leaf; |
| 152427 | + ExprClearVVAProperties(p); |
| 152250 | 152428 | p->iAgg = -1; |
| 152251 | 152429 | p->pLeft = p->pRight = 0; |
| 152252 | 152430 | p->x.pList = 0; |
| 152253 | 152431 | p->pAggInfo = 0; |
| 152254 | 152432 | p->y.pTab = 0; |
| | @@ -162084,15 +162262,10 @@ |
| 162084 | 162262 | createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0); |
| 162085 | 162263 | createCollation(db, "RTRIM", SQLITE_UTF8, 0, rtrimCollFunc, 0); |
| 162086 | 162264 | if( db->mallocFailed ){ |
| 162087 | 162265 | goto opendb_out; |
| 162088 | 162266 | } |
| 162089 | | - /* EVIDENCE-OF: R-08308-17224 The default collating function for all |
| 162090 | | - ** strings is BINARY. |
| 162091 | | - */ |
| 162092 | | - db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, sqlite3StrBINARY, 0); |
| 162093 | | - assert( db->pDfltColl!=0 ); |
| 162094 | 162267 | |
| 162095 | 162268 | /* Parse the filename/URI argument |
| 162096 | 162269 | ** |
| 162097 | 162270 | ** Only allow sensible combinations of bits in the flags argument. |
| 162098 | 162271 | ** Throw an error if any non-sense combination is used. If we |
| | @@ -162133,11 +162306,13 @@ |
| 162133 | 162306 | sqlite3Error(db, rc); |
| 162134 | 162307 | goto opendb_out; |
| 162135 | 162308 | } |
| 162136 | 162309 | sqlite3BtreeEnter(db->aDb[0].pBt); |
| 162137 | 162310 | db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt); |
| 162138 | | - if( !db->mallocFailed ) ENC(db) = SCHEMA_ENC(db); |
| 162311 | + if( !db->mallocFailed ){ |
| 162312 | + sqlite3SetTextEncoding(db, SCHEMA_ENC(db)); |
| 162313 | + } |
| 162139 | 162314 | sqlite3BtreeLeave(db->aDb[0].pBt); |
| 162140 | 162315 | db->aDb[1].pSchema = sqlite3SchemaGet(db, 0); |
| 162141 | 162316 | |
| 162142 | 162317 | /* The default safety_level for the main database is FULL; for the temp |
| 162143 | 162318 | ** database it is OFF. This matches the pager layer defaults. |
| | @@ -166664,10 +166839,11 @@ |
| 166664 | 166839 | const char *zEnd = &zCsr[nNode];/* End of interior node buffer */ |
| 166665 | 166840 | char *zBuffer = 0; /* Buffer to load terms into */ |
| 166666 | 166841 | i64 nAlloc = 0; /* Size of allocated buffer */ |
| 166667 | 166842 | int isFirstTerm = 1; /* True when processing first term on page */ |
| 166668 | 166843 | sqlite3_int64 iChild; /* Block id of child node to descend to */ |
| 166844 | + int nBuffer = 0; /* Total term size */ |
| 166669 | 166845 | |
| 166670 | 166846 | /* Skip over the 'height' varint that occurs at the start of every |
| 166671 | 166847 | ** interior node. Then load the blockid of the left-child of the b-tree |
| 166672 | 166848 | ** node into variable iChild. |
| 166673 | 166849 | ** |
| | @@ -166688,16 +166864,19 @@ |
| 166688 | 166864 | |
| 166689 | 166865 | while( zCsr<zEnd && (piFirst || piLast) ){ |
| 166690 | 166866 | int cmp; /* memcmp() result */ |
| 166691 | 166867 | int nSuffix; /* Size of term suffix */ |
| 166692 | 166868 | int nPrefix = 0; /* Size of term prefix */ |
| 166693 | | - int nBuffer; /* Total term size */ |
| 166694 | 166869 | |
| 166695 | 166870 | /* Load the next term on the node into zBuffer. Use realloc() to expand |
| 166696 | 166871 | ** the size of zBuffer if required. */ |
| 166697 | 166872 | if( !isFirstTerm ){ |
| 166698 | 166873 | zCsr += fts3GetVarint32(zCsr, &nPrefix); |
| 166874 | + if( nPrefix>nBuffer ){ |
| 166875 | + rc = FTS_CORRUPT_VTAB; |
| 166876 | + goto finish_scan; |
| 166877 | + } |
| 166699 | 166878 | } |
| 166700 | 166879 | isFirstTerm = 0; |
| 166701 | 166880 | zCsr += fts3GetVarint32(zCsr, &nSuffix); |
| 166702 | 166881 | |
| 166703 | 166882 | assert( nPrefix>=0 && nSuffix>=0 ); |
| | @@ -179916,10 +180095,16 @@ |
| 179916 | 180095 | |
| 179917 | 180096 | /* If nSeg is less that zero, then there is no level with at least |
| 179918 | 180097 | ** nMin segments and no hint in the %_stat table. No work to do. |
| 179919 | 180098 | ** Exit early in this case. */ |
| 179920 | 180099 | if( nSeg<=0 ) break; |
| 180100 | + |
| 180101 | + assert( nMod<=0x7FFFFFFF ); |
| 180102 | + if( iAbsLevel<0 || iAbsLevel>(nMod<<32) ){ |
| 180103 | + rc = FTS_CORRUPT_VTAB; |
| 180104 | + break; |
| 180105 | + } |
| 179921 | 180106 | |
| 179922 | 180107 | /* Open a cursor to iterate through the contents of the oldest nSeg |
| 179923 | 180108 | ** indexes of absolute level iAbsLevel. If this cursor is opened using |
| 179924 | 180109 | ** the 'hint' parameters, it is possible that there are less than nSeg |
| 179925 | 180110 | ** segments available in level iAbsLevel. In this case, no work is |
| | @@ -189652,12 +189837,14 @@ |
| 189652 | 189837 | pRtree->nAux++; |
| 189653 | 189838 | sqlite3_str_appendf(pSql, ",%.*s", rtreeTokenLength(zArg+1), zArg+1); |
| 189654 | 189839 | }else if( pRtree->nAux>0 ){ |
| 189655 | 189840 | break; |
| 189656 | 189841 | }else{ |
| 189842 | + static const char *azFormat[] = {",%.*s REAL", ",%.*s INT"}; |
| 189657 | 189843 | pRtree->nDim2++; |
| 189658 | | - sqlite3_str_appendf(pSql, ",%.*s NUM", rtreeTokenLength(zArg), zArg); |
| 189844 | + sqlite3_str_appendf(pSql, azFormat[eCoordType], |
| 189845 | + rtreeTokenLength(zArg), zArg); |
| 189659 | 189846 | } |
| 189660 | 189847 | } |
| 189661 | 189848 | sqlite3_str_appendf(pSql, ");"); |
| 189662 | 189849 | zSql = sqlite3_str_finish(pSql); |
| 189663 | 189850 | if( !zSql ){ |
| | @@ -192389,11 +192576,11 @@ |
| 192389 | 192576 | ** 1. uPattern is an unescaped match-all character "%", |
| 192390 | 192577 | ** 2. uPattern is an unescaped match-one character "_", |
| 192391 | 192578 | ** 3. uPattern is an unescaped escape character, or |
| 192392 | 192579 | ** 4. uPattern is to be handled as an ordinary character |
| 192393 | 192580 | */ |
| 192394 | | - if( !prevEscape && uPattern==MATCH_ALL ){ |
| 192581 | + if( uPattern==MATCH_ALL && !prevEscape && uPattern!=(uint32_t)uEsc ){ |
| 192395 | 192582 | /* Case 1. */ |
| 192396 | 192583 | uint8_t c; |
| 192397 | 192584 | |
| 192398 | 192585 | /* Skip any MATCH_ALL or MATCH_ONE characters that follow a |
| 192399 | 192586 | ** MATCH_ALL. For each MATCH_ONE, skip one character in the |
| | @@ -192415,16 +192602,16 @@ |
| 192415 | 192602 | } |
| 192416 | 192603 | SQLITE_ICU_SKIP_UTF8(zString); |
| 192417 | 192604 | } |
| 192418 | 192605 | return 0; |
| 192419 | 192606 | |
| 192420 | | - }else if( !prevEscape && uPattern==MATCH_ONE ){ |
| 192607 | + }else if( uPattern==MATCH_ONE && !prevEscape && uPattern!=(uint32_t)uEsc ){ |
| 192421 | 192608 | /* Case 2. */ |
| 192422 | 192609 | if( *zString==0 ) return 0; |
| 192423 | 192610 | SQLITE_ICU_SKIP_UTF8(zString); |
| 192424 | 192611 | |
| 192425 | | - }else if( !prevEscape && uPattern==(uint32_t)uEsc){ |
| 192612 | + }else if( uPattern==(uint32_t)uEsc && !prevEscape ){ |
| 192426 | 192613 | /* Case 3. */ |
| 192427 | 192614 | prevEscape = 1; |
| 192428 | 192615 | |
| 192429 | 192616 | }else{ |
| 192430 | 192617 | /* Case 4. */ |
| | @@ -199222,10 +199409,11 @@ |
| 199222 | 199409 | } |
| 199223 | 199410 | } |
| 199224 | 199411 | i = 0; |
| 199225 | 199412 | if( iSchema>=0 ){ |
| 199226 | 199413 | pIdxInfo->aConstraintUsage[iSchema].argvIndex = ++i; |
| 199414 | + pIdxInfo->aConstraintUsage[iSchema].omit = 1; |
| 199227 | 199415 | pIdxInfo->idxNum |= 0x01; |
| 199228 | 199416 | } |
| 199229 | 199417 | if( iName>=0 ){ |
| 199230 | 199418 | pIdxInfo->aConstraintUsage[iName].argvIndex = ++i; |
| 199231 | 199419 | pIdxInfo->idxNum |= 0x02; |
| | @@ -199436,11 +199624,13 @@ |
| 199436 | 199624 | assert( nPayload>=(u32)nLocal ); |
| 199437 | 199625 | assert( nLocal<=(nUsable-35) ); |
| 199438 | 199626 | if( nPayload>(u32)nLocal ){ |
| 199439 | 199627 | int j; |
| 199440 | 199628 | int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4); |
| 199441 | | - if( iOff+nLocal>nUsable ) goto statPageIsCorrupt; |
| 199629 | + if( iOff+nLocal>nUsable || nPayload>0x7fffffff ){ |
| 199630 | + goto statPageIsCorrupt; |
| 199631 | + } |
| 199442 | 199632 | pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4); |
| 199443 | 199633 | pCell->nOvfl = nOvfl; |
| 199444 | 199634 | pCell->aOvfl = sqlite3_malloc64(sizeof(u32)*nOvfl); |
| 199445 | 199635 | if( pCell->aOvfl==0 ) return SQLITE_NOMEM_BKPT; |
| 199446 | 199636 | pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]); |
| | @@ -203769,11 +203959,11 @@ |
| 203769 | 203959 | const char *zSep = ""; |
| 203770 | 203960 | int rc = SQLITE_OK; |
| 203771 | 203961 | SessionBuffer buf = {0, 0, 0}; |
| 203772 | 203962 | int nPk = 0; |
| 203773 | 203963 | |
| 203774 | | - sessionAppendStr(&buf, "DELETE FROM ", &rc); |
| 203964 | + sessionAppendStr(&buf, "DELETE FROM main.", &rc); |
| 203775 | 203965 | sessionAppendIdent(&buf, zTab, &rc); |
| 203776 | 203966 | sessionAppendStr(&buf, " WHERE ", &rc); |
| 203777 | 203967 | |
| 203778 | 203968 | for(i=0; i<p->nCol; i++){ |
| 203779 | 203969 | if( p->abPK[i] ){ |
| | @@ -203852,11 +204042,11 @@ |
| 203852 | 204042 | int i; |
| 203853 | 204043 | const char *zSep = ""; |
| 203854 | 204044 | SessionBuffer buf = {0, 0, 0}; |
| 203855 | 204045 | |
| 203856 | 204046 | /* Append "UPDATE tbl SET " */ |
| 203857 | | - sessionAppendStr(&buf, "UPDATE ", &rc); |
| 204047 | + sessionAppendStr(&buf, "UPDATE main.", &rc); |
| 203858 | 204048 | sessionAppendIdent(&buf, zTab, &rc); |
| 203859 | 204049 | sessionAppendStr(&buf, " SET ", &rc); |
| 203860 | 204050 | |
| 203861 | 204051 | /* Append the assignments */ |
| 203862 | 204052 | for(i=0; i<p->nCol; i++){ |
| | @@ -223538,11 +223728,11 @@ |
| 223538 | 223728 | int nArg, /* Number of args */ |
| 223539 | 223729 | sqlite3_value **apUnused /* Function arguments */ |
| 223540 | 223730 | ){ |
| 223541 | 223731 | assert( nArg==0 ); |
| 223542 | 223732 | UNUSED_PARAM2(nArg, apUnused); |
| 223543 | | - sqlite3_result_text(pCtx, "fts5: 2020-02-27 11:32:14 bfb09371d452d5d4dacab2ec476880bc729952f44ac0e5de90ea7ba203243c8c", -1, SQLITE_TRANSIENT); |
| 223733 | + sqlite3_result_text(pCtx, "fts5: 2020-03-21 23:10:38 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84f525", -1, SQLITE_TRANSIENT); |
| 223544 | 223734 | } |
| 223545 | 223735 | |
| 223546 | 223736 | /* |
| 223547 | 223737 | ** Return true if zName is the extension on one of the shadow tables used |
| 223548 | 223738 | ** by this module. |
| | @@ -228320,12 +228510,12 @@ |
| 228320 | 228510 | } |
| 228321 | 228511 | #endif /* SQLITE_CORE */ |
| 228322 | 228512 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 228323 | 228513 | |
| 228324 | 228514 | /************** End of stmt.c ************************************************/ |
| 228325 | | -#if __LINE__!=228325 |
| 228515 | +#if __LINE__!=228515 |
| 228326 | 228516 | #undef SQLITE_SOURCE_ID |
| 228327 | | -#define SQLITE_SOURCE_ID "2020-02-27 16:21:39 951b39ca74c9bd933139e099d5555283278db475f410f202c162e5d1e6aealt2" |
| 228517 | +#define SQLITE_SOURCE_ID "2020-03-21 23:10:38 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84alt2" |
| 228328 | 228518 | #endif |
| 228329 | 228519 | /* Return the source-id for this library */ |
| 228330 | 228520 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 228331 | 228521 | /************************** End of sqlite3.c ******************************/ |
| 228332 | 228522 | |