📄 vdbeint.h
字号:
** There is a typedef for this structure in sqlite.h. So all routines,** even the public interface to SQLite, can use a pointer to this structure.** But this file is the only place where the internal details of this** structure are known.**** This structure is defined inside of vdbe.c because it uses substructures** (Mem) which are only defined there.*/struct sqlite3_context { FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */ VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */ Mem s; /* The return value is stored here */ void *pAgg; /* Aggregate context */ u8 isError; /* Set to true for an error */ int cnt; /* Number of times that the step function has been called */ CollSeq *pColl;};/*** An Agg structure describes an Aggregator. Each Agg consists of** zero or more Aggregator elements (AggElem). Each AggElem contains** a key and one or more values. The values are used in processing** aggregate functions in a SELECT. The key is used to implement** the GROUP BY clause of a select.*/typedef struct Agg Agg;typedef struct AggElem AggElem;struct Agg { int nMem; /* Number of values stored in each AggElem */ AggElem *pCurrent; /* The AggElem currently in focus */ FuncDef **apFunc; /* Information about aggregate functions */ Btree *pBtree; /* The tmp. btree used to group elements, if required. */ BtCursor *pCsr; /* Read/write cursor to the table in pBtree */ int nTab; /* Root page of the table in pBtree */ u8 searching; /* True between the first AggNext and AggReset */};struct AggElem { char *zKey; /* The key to this AggElem */ int nKey; /* Number of bytes in the key, including '\0' at end */ Mem aMem[1]; /* The values for this AggElem */};/*** A Set structure is used for quick testing to see if a value** is part of a small set. Sets are used to implement code like** this:** x.y IN ('hi','hoo','hum')*/typedef struct Set Set;struct Set { Hash hash; /* A set is just a hash table */ HashElem *prev; /* Previously accessed hash elemen */};/*** A Keylist is a bunch of keys into a table. The keylist can** grow without bound. The keylist stores the ROWIDs of database** records that need to be deleted or updated.*/typedef struct Keylist Keylist;struct Keylist { int nKey; /* Number of slots in aKey[] */ int nUsed; /* Next unwritten slot in aKey[] */ int nRead; /* Next unread slot in aKey[] */ Keylist *pNext; /* Next block of keys */ i64 aKey[1]; /* One or more keys. Extra space allocated as needed */};/*** A Context stores the last insert rowid, the last statement change count,** and the current statement change count (i.e. changes since last statement).** The current keylist is also stored in the context.** Elements of Context structure type make up the ContextStack, which is** updated by the ContextPush and ContextPop opcodes (used by triggers).** The context is pushed before executing a trigger a popped when the** trigger finishes.*/typedef struct Context Context;struct Context { int lastRowid; /* Last insert rowid (sqlite3.lastRowid) */ int nChange; /* Statement changes (Vdbe.nChanges) */ Keylist *pList; /* Records that will participate in a DELETE or UPDATE */};/*** An instance of the virtual machine. This structure contains the complete** state of the virtual machine.**** The "sqlite3_stmt" structure pointer that is returned by sqlite3_compile()** is really a pointer to an instance of this structure.*/struct Vdbe { sqlite3 *db; /* The whole database */ Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ FILE *trace; /* Write an execution trace here, if not NULL */ int nOp; /* Number of instructions in the program */ int nOpAlloc; /* Number of slots allocated for aOp[] */ Op *aOp; /* Space to hold the virtual machine's program */ int nLabel; /* Number of labels used */ int nLabelAlloc; /* Number of slots allocated in aLabel[] */ int *aLabel; /* Space to hold the labels */ Mem *aStack; /* The operand stack, except string values */ Mem *pTos; /* Top entry in the operand stack */ Mem **apArg; /* Arguments to currently executing user function */ Mem *aColName; /* Column names to return */ int nCursor; /* Number of slots in apCsr[] */ Cursor **apCsr; /* One element of this array for each open cursor */ Sorter *pSort; /* A linked list of objects to be sorted */ Sorter *pSortTail; /* Last element on the pSort list */ int nVar; /* Number of entries in aVar[] */ Mem *aVar; /* Values for the OP_Variable opcode. */ char **azVar; /* Name of variables */ int okVar; /* True if azVar[] has been initialized */ int magic; /* Magic number for sanity checking */ int nMem; /* Number of memory locations currently allocated */ Mem *aMem; /* The memory locations */ int nAgg; /* Number of elements in apAgg */ Agg *apAgg; /* Array of aggregate contexts */ Agg *pAgg; /* Current aggregate context */ int nCallback; /* Number of callbacks invoked so far */ Keylist *pList; /* A list of ROWIDs */ int contextStackTop; /* Index of top element in the context stack */ int contextStackDepth; /* The size of the "context" stack */ Context *contextStack; /* Stack used by opcodes ContextPush & ContextPop*/ int pc; /* The program counter */ int rc; /* Value to return */ unsigned uniqueCnt; /* Used by OP_MakeRecord when P2!=0 */ int errorAction; /* Recovery action to do in case of an error */ int inTempTrans; /* True if temp database is transactioned */ int returnStack[100]; /* Return address stack for OP_Gosub & OP_Return */ int returnDepth; /* Next unused element in returnStack[] */ int nResColumn; /* Number of columns in one row of the result set */ char **azResColumn; /* Values for one row of result */ int popStack; /* Pop the stack this much on entry to VdbeExec() */ char *zErrMsg; /* Error message written here */ u8 resOnStack; /* True if there are result values on the stack */ u8 explain; /* True if EXPLAIN present on SQL command */ u8 changeCntOn; /* True to update the change-counter */ u8 aborted; /* True if ROLLBACK in another VM causes an abort */ u8 expired; /* True if the VM needs to be recompiled */ int nChange; /* Number of db changes made since last reset */};/*** The following are allowed values for Vdbe.magic*/#define VDBE_MAGIC_INIT 0x26bceaa5 /* Building a VDBE program */#define VDBE_MAGIC_RUN 0xbdf20da3 /* VDBE is ready to execute */#define VDBE_MAGIC_HALT 0x519c2973 /* VDBE has completed execution */#define VDBE_MAGIC_DEAD 0xb606c3c8 /* The VDBE has been deallocated *//*** Function prototypes*/void sqlite3VdbeFreeCursor(Cursor*);void sqlite3VdbeSorterReset(Vdbe*);int sqlite3VdbeAggReset(sqlite3*, Agg *, KeyInfo *);void sqlite3VdbeKeylistFree(Keylist*);void sqliteVdbePopStack(Vdbe*,int);int sqlite3VdbeCursorMoveto(Cursor*);#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)void sqlite3VdbePrintOp(FILE*, int, Op*);#endif#ifdef SQLITE_DEBUGvoid sqlite3VdbePrintSql(Vdbe*);#endifint sqlite3VdbeSerialTypeLen(u32);u32 sqlite3VdbeSerialType(Mem*);int sqlite3VdbeSerialPut(unsigned char*, Mem*);int sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);int sqlite3VdbeIdxKeyCompare(Cursor*, int , const unsigned char*, int*);int sqlite3VdbeIdxRowid(BtCursor *, i64 *);int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);int sqlite3VdbeRecordCompare(void*,int,const void*,int, const void*);int sqlite3VdbeIdxRowidLen(int,const u8*);int sqlite3VdbeExec(Vdbe*);int sqlite3VdbeList(Vdbe*);int sqlite3VdbeHalt(Vdbe*);int sqlite3VdbeChangeEncoding(Mem *, int);int sqlite3VdbeMemCopy(Mem*, const Mem*);void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);int sqlite3VdbeMemMove(Mem*, Mem*);int sqlite3VdbeMemNulTerminate(Mem*);int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*));void sqlite3VdbeMemSetInt64(Mem*, i64);void sqlite3VdbeMemSetDouble(Mem*, double);void sqlite3VdbeMemSetNull(Mem*);int sqlite3VdbeMemMakeWriteable(Mem*);int sqlite3VdbeMemDynamicify(Mem*);int sqlite3VdbeMemStringify(Mem*, int);i64 sqlite3VdbeIntValue(Mem*);int sqlite3VdbeMemIntegerify(Mem*);double sqlite3VdbeRealValue(Mem*);int sqlite3VdbeMemRealify(Mem*);int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);void sqlite3VdbeMemRelease(Mem *p);#ifndef NDEBUGvoid sqlite3VdbeMemSanity(Mem*, u8);int sqlite3VdbeOpcodeNoPush(u8);#endifint sqlite3VdbeMemTranslate(Mem*, u8);void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf, int nBuf);int sqlite3VdbeMemHandleBom(Mem *pMem);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -