#ifndef SQLITE_VDBEINT_H
#define SQLITE_VDBEINT_H
#ifndef SQLITE_MAX_SCHEMA_RETRY
# define SQLITE_MAX_SCHEMA_RETRY 50
#endif
#if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) \
|| defined(VDBE_PROFILE) || defined(SQLITE_DEBUG) \
|| defined(SQLITE_ENABLE_BYTECODE_VTAB)
# define VDBE_DISPLAY_P4 1
#else
# define VDBE_DISPLAY_P4 0
#endif
typedef struct VdbeOp Op;
typedef unsigned Bool;
typedef struct VdbeSorter VdbeSorter;
typedef struct AuxData AuxData;
#define CURTYPE_BTREE 0
#define CURTYPE_SORTER 1
#define CURTYPE_VTAB 2
#define CURTYPE_PSEUDO 3
typedef struct VdbeCursor VdbeCursor;
struct VdbeCursor {
u8 eCurType;
i8 iDb;
u8 nullRow;
u8 deferredMoveto;
u8 isTable;
#ifdef SQLITE_DEBUG
u8 seekOp;
u8 wrFlag;
#endif
Bool isEphemeral:1;
Bool useRandomRowid:1;
Bool isOrdered:1;
Bool noReuse:1;
u16 seekHit;
union {
Btree *pBtx;
u32 *aAltMap;
} ub;
i64 seqCount;
u32 cacheStatus;
int seekResult;
VdbeCursor *pAltCursor;
union {
BtCursor *pCursor;
sqlite3_vtab_cursor *pVCur;
VdbeSorter *pSorter;
} uc;
KeyInfo *pKeyInfo;
u32 iHdrOffset;
Pgno pgnoRoot;
i16 nField;
u16 nHdrParsed;
i64 movetoTarget;
u32 *aOffset;
const u8 *aRow;
u32 payloadSize;
u32 szRow;
#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
u64 maskUsed;
#endif
u32 aType[1];
};
#define IsNullCursor(P) \
((P)->eCurType==CURTYPE_PSEUDO && (P)->nullRow && (P)->seekResult==0)
#define CACHE_STALE 0
typedef struct VdbeFrame VdbeFrame;
struct VdbeFrame {
Vdbe *v;
VdbeFrame *pParent;
Op *aOp;
Mem *aMem;
VdbeCursor **apCsr;
u8 *aOnce;
void *token;
i64 lastRowid;
AuxData *pAuxData;
#if SQLITE_DEBUG
u32 iFrameMagic;
#endif
int nCursor;
int pc;
int nOp;
int nMem;
int nChildMem;
int nChildCsr;
i64 nChange;
i64 nDbChange;
};
#define SQLITE_FRAME_MAGIC 0x879fb71e
#define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
struct sqlite3_value {
union MemValue {
double r;
i64 i;
int nZero;
const char *zPType;
FuncDef *pDef;
} u;
char *z;
int n;
u16 flags;
u8 enc;
u8 eSubtype;
sqlite3 *db;
int szMalloc;
u32 uTemp;
char *zMalloc;
void (*xDel)(void*);
#ifdef SQLITE_DEBUG
Mem *pScopyFrom;
u16 mScopyFlags;
#endif
};
#define MEMCELLSIZE offsetof(Mem,db)
#define MEM_Undefined 0x0000
#define MEM_Null 0x0001
#define MEM_Str 0x0002
#define MEM_Int 0x0004
#define MEM_Real 0x0008
#define MEM_Blob 0x0010
#define MEM_IntReal 0x0020
#define MEM_AffMask 0x003f
#define MEM_FromBind 0x0040
#define MEM_Cleared 0x0100
#define MEM_Term 0x0200
#define MEM_Zero 0x0400
#define MEM_Subtype 0x0800
#define MEM_TypeMask 0x0dbf
#define MEM_Dyn 0x1000
#define MEM_Static 0x2000
#define MEM_Ephem 0x4000
#define MEM_Agg 0x8000
#define VdbeMemDynamic(X) \
(((X)->flags&(MEM_Agg|MEM_Dyn))!=0)
#define MemSetTypeFlag(p, f) \
((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
#define MemNullNochng(X) \
(((X)->flags&MEM_TypeMask)==(MEM_Null|MEM_Zero) \
&& (X)->n==0 && (X)->u.nZero==0)
#ifdef SQLITE_DEBUG
#define memIsValid(M) ((M)->flags & MEM_AffMask)!=0
#endif
struct AuxData {
int iAuxOp;
int iAuxArg;
void *pAux;
void (*xDeleteAux)(void*);
AuxData *pNextAux;
};
struct sqlite3_context {
Mem *pOut;
FuncDef *pFunc;
Mem *pMem;
Vdbe *pVdbe;
int iOp;
int isError;
u8 enc;
u8 skipFlag;
u8 argc;
sqlite3_value *argv[1];
};
typedef unsigned bft;
typedef struct ScanStatus ScanStatus;
struct ScanStatus {
int addrExplain;
int aAddrRange[6];
int addrLoop;
int addrVisit;
int iSelectID;
LogEst nEst;
char *zName;
};
typedef struct DblquoteStr DblquoteStr;
struct DblquoteStr {
DblquoteStr *pNextStr;
char z[8];
};
struct Vdbe {
sqlite3 *db;
Vdbe **ppVPrev,*pVNext;
Parse *pParse;
ynVar nVar;
int nMem;
int nCursor;
u32 cacheCtr;
int pc;
int rc;
i64 nChange;
int iStatement;
i64 iCurrentTime;
i64 nFkConstraint;
i64 nStmtDefCons;
i64 nStmtDefImmCons;
Mem *aMem;
Mem **apArg;
VdbeCursor **apCsr;
Mem *aVar;
Op *aOp;
int nOp;
int nOpAlloc;
Mem *aColName;
Mem *pResultRow;
char *zErrMsg;
VList *pVList;
#ifndef SQLITE_OMIT_TRACE
i64 startTime;
#endif
#ifdef SQLITE_DEBUG
int rcApp;
u32 nWrite;
#endif
u16 nResColumn;
u8 errorAction;
u8 minWriteFileFormat;
u8 prepFlags;
u8 eVdbeState;
bft expired:2;
bft explain:2;
bft changeCntOn:1;
bft usesStmtJournal:1;
bft readOnly:1;
bft bIsReader:1;
yDbMask btreeMask;
yDbMask lockMask;
u32 aCounter[9];
char *zSql;
#ifdef SQLITE_ENABLE_NORMALIZE
char *zNormSql;
DblquoteStr *pDblStr;
#endif
void *pFree;
VdbeFrame *pFrame;
VdbeFrame *pDelFrame;
int nFrame;
u32 expmask;
SubProgram *pProgram;
AuxData *pAuxData;
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
int nScan;
ScanStatus *aScan;
#endif
};
#define VDBE_INIT_STATE 0
#define VDBE_READY_STATE 1
#define VDBE_RUN_STATE 2
#define VDBE_HALT_STATE 3
struct PreUpdate {
Vdbe *v;
VdbeCursor *pCsr;
int op;
u8 *aRecord;
KeyInfo keyinfo;
UnpackedRecord *pUnpacked;
UnpackedRecord *pNewUnpacked;
int iNewReg;
int iBlobWrite;
i64 iKey1;
i64 iKey2;
Mem *aNew;
Table *pTab;
Index *pPk;
};
typedef struct ValueList ValueList;
struct ValueList {
BtCursor *pCsr;
sqlite3_value *pOut;
};
#ifndef SQLITE_AMALGAMATION
extern const u8 sqlite3SmallTypeSizes[];
#endif
void sqlite3VdbeError(Vdbe*, const char *, ...);
void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
void sqlite3VdbeFreeCursorNN(Vdbe*,VdbeCursor*);
void sqliteVdbePopStack(Vdbe*,int);
int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p);
int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*);
int sqlite3VdbeCursorRestore(VdbeCursor*);
u32 sqlite3VdbeSerialTypeLen(u32);
u8 sqlite3VdbeOneByteSerialTypeLen(u8);
#ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
u64 sqlite3FloatSwap(u64 in);
# define swapMixedEndianFloat(X) X = sqlite3FloatSwap(X)
#else
# define swapMixedEndianFloat(X)
#endif
void sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
void sqlite3VdbeDeleteAuxData(sqlite3*, AuxData**, int, int);
int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*,int*);
int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*);
int sqlite3VdbeExec(Vdbe*);
#if !defined(SQLITE_OMIT_EXPLAIN) || defined(SQLITE_ENABLE_BYTECODE_VTAB)
int sqlite3VdbeNextOpcode(Vdbe*,Mem*,int,int*,int*,Op**);
char *sqlite3VdbeDisplayP4(sqlite3*,Op*);
#endif
#if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS)
char *sqlite3VdbeDisplayComment(sqlite3*,const Op*,const char*);
#endif
#if !defined(SQLITE_OMIT_EXPLAIN)
int sqlite3VdbeList(Vdbe*);
#endif
int sqlite3VdbeHalt(Vdbe*);
int sqlite3VdbeChangeEncoding(Mem *, int);
int sqlite3VdbeMemTooBig(Mem*);
int sqlite3VdbeMemCopy(Mem*, const Mem*);
void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);
void sqlite3VdbeMemMove(Mem*, Mem*);
int sqlite3VdbeMemNulTerminate(Mem*);
int sqlite3VdbeMemSetStr(Mem*, const char*, i64, u8, void(*)(void*));
void sqlite3VdbeMemSetInt64(Mem*, i64);
#ifdef SQLITE_OMIT_FLOATING_POINT
# define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64
#else
void sqlite3VdbeMemSetDouble(Mem*, double);
#endif
void sqlite3VdbeMemSetPointer(Mem*, void*, const char*, void(*)(void*));
void sqlite3VdbeMemInit(Mem*,sqlite3*,u16);
void sqlite3VdbeMemSetNull(Mem*);
#ifndef SQLITE_OMIT_INCRBLOB
void sqlite3VdbeMemSetZeroBlob(Mem*,int);
#else
int sqlite3VdbeMemSetZeroBlob(Mem*,int);
#endif
#ifdef SQLITE_DEBUG
int sqlite3VdbeMemIsRowSet(const Mem*);
#endif
int sqlite3VdbeMemSetRowSet(Mem*);
int sqlite3VdbeMemMakeWriteable(Mem*);
int sqlite3VdbeMemStringify(Mem*, u8, u8);
int sqlite3IntFloatCompare(i64,double);
i64 sqlite3VdbeIntValue(const Mem*);
int sqlite3VdbeMemIntegerify(Mem*);
double sqlite3VdbeRealValue(Mem*);
int sqlite3VdbeBooleanValue(Mem*, int ifNull);
void sqlite3VdbeIntegerAffinity(Mem*);
int sqlite3VdbeMemRealify(Mem*);
int sqlite3VdbeMemNumerify(Mem*);
int sqlite3VdbeMemCast(Mem*,u8,u8);
int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
int sqlite3VdbeMemFromBtreeZeroOffset(BtCursor*,u32,Mem*);
void sqlite3VdbeMemRelease(Mem *p);
void sqlite3VdbeMemReleaseMalloc(Mem*p);
int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
#ifndef SQLITE_OMIT_WINDOWFUNC
int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*);
#endif
#if !defined(SQLITE_OMIT_EXPLAIN) || defined(SQLITE_ENABLE_BYTECODE_VTAB)
const char *sqlite3OpcodeName(int);
#endif
int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
int sqlite3VdbeMemClearAndResize(Mem *pMem, int n);
int sqlite3VdbeCloseStatement(Vdbe *, int);
#ifdef SQLITE_DEBUG
int sqlite3VdbeFrameIsValid(VdbeFrame*);
#endif
void sqlite3VdbeFrameMemDel(void*);
void sqlite3VdbeFrameDelete(VdbeFrame*);
int sqlite3VdbeFrameRestore(VdbeFrame *);
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
void sqlite3VdbePreUpdateHook(
Vdbe*,VdbeCursor*,int,const char*,Table*,i64,int,int);
#endif
int sqlite3VdbeTransferError(Vdbe *p);
int sqlite3VdbeSorterInit(sqlite3 *, int, VdbeCursor *);
void sqlite3VdbeSorterReset(sqlite3 *, VdbeSorter *);
void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *);
int sqlite3VdbeSorterRewind(const VdbeCursor *, int *);
int sqlite3VdbeSorterWrite(const VdbeCursor *, Mem *);
int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int, int *);
void sqlite3VdbeValueListFree(void*);
#ifdef SQLITE_DEBUG
void sqlite3VdbeIncrWriteCounter(Vdbe*, VdbeCursor*);
void sqlite3VdbeAssertAbortable(Vdbe*);
#else
# define sqlite3VdbeIncrWriteCounter(V,C)
# define sqlite3VdbeAssertAbortable(V)
#endif
#if !defined(SQLITE_OMIT_SHARED_CACHE)
void sqlite3VdbeEnter(Vdbe*);
#else
# define sqlite3VdbeEnter(X)
#endif
#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
void sqlite3VdbeLeave(Vdbe*);
#else
# define sqlite3VdbeLeave(X)
#endif
#ifdef SQLITE_DEBUG
void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*);
int sqlite3VdbeCheckMemInvariants(Mem*);
#endif
#ifndef SQLITE_OMIT_FOREIGN_KEY
int sqlite3VdbeCheckFk(Vdbe *, int);
#else
# define sqlite3VdbeCheckFk(p,i) 0
#endif
#ifdef SQLITE_DEBUG
void sqlite3VdbePrintSql(Vdbe*);
void sqlite3VdbeMemPrettyPrint(Mem *pMem, StrAccum *pStr);
#endif
#ifndef SQLITE_OMIT_UTF16
int sqlite3VdbeMemTranslate(Mem*, u8);
int sqlite3VdbeMemHandleBom(Mem *pMem);
#endif
#ifndef SQLITE_OMIT_INCRBLOB
int sqlite3VdbeMemExpandBlob(Mem *);
#define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
#else
#define sqlite3VdbeMemExpandBlob(x) SQLITE_OK
#define ExpandBlob(P) SQLITE_OK
#endif
#endif