📄 sqliteint.h
字号:
struct WhereLevel { int iFrom; /* Which entry in the FROM clause */ int flags; /* Flags associated with this level */ int iMem; /* First memory cell used by this level */ int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */ Index *pIdx; /* Index used. NULL if no index */ int iTabCur; /* The VDBE cursor used to access the table */ int iIdxCur; /* The VDBE cursor used to acesss pIdx */ int brk; /* Jump here to break out of the loop */ int nxt; /* Jump here to start the next IN combination */ int cont; /* Jump here to continue with the next loop cycle */ int top; /* First instruction of interior of the loop */ int op, p1, p2; /* Opcode used to terminate the loop */ int nEq; /* Number of == or IN constraints on this loop */ int nIn; /* Number of IN operators constraining this loop */ struct InLoop { int iCur; /* The VDBE cursor used by this IN operator */ int topAddr; /* Top of the IN loop */ } *aInLoop; /* Information about each nested IN operator */ sqlite3_index_info *pBestIdx; /* Index information for this level */ /* The following field is really not part of the current level. But ** we need a place to cache index information for each table in the ** FROM clause and the WhereLevel structure is a convenient place. */ sqlite3_index_info *pIdxInfo; /* Index info for n-th source table */};/*** The WHERE clause processing routine has two halves. The** first part does the start of the WHERE loop and the second** half does the tail of the WHERE loop. An instance of** this structure is returned by the first half and passed** into the second half to give some continuity.*/struct WhereInfo { Parse *pParse; SrcList *pTabList; /* List of tables in the join */ int iTop; /* The very beginning of the WHERE loop */ int iContinue; /* Jump here to continue with next record */ int iBreak; /* Jump here to break out of the loop */ int nLevel; /* Number of nested loop */ sqlite3_index_info **apInfo; /* Array of pointers to index info structures */ WhereLevel a[1]; /* Information about each nest loop in the WHERE */};/*** A NameContext defines a context in which to resolve table and column** names. The context consists of a list of tables (the pSrcList) field and** a list of named expression (pEList). The named expression list may** be NULL. The pSrc corresponds to the FROM clause of a SELECT or** to the table being operated on by INSERT, UPDATE, or DELETE. The** pEList corresponds to the result set of a SELECT and is NULL for** other statements.**** NameContexts can be nested. When resolving names, the inner-most ** context is searched first. If no match is found, the next outer** context is checked. If there is still no match, the next context** is checked. This process continues until either a match is found** or all contexts are check. When a match is found, the nRef member of** the context containing the match is incremented. **** Each subquery gets a new NameContext. The pNext field points to the** NameContext in the parent query. Thus the process of scanning the** NameContext list corresponds to searching through successively outer** subqueries looking for a match.*/struct NameContext { Parse *pParse; /* The parser */ SrcList *pSrcList; /* One or more tables used to resolve names */ ExprList *pEList; /* Optional list of named expressions */ int nRef; /* Number of names resolved by this context */ int nErr; /* Number of errors encountered while resolving names */ u8 allowAgg; /* Aggregate functions allowed here */ u8 hasAgg; /* True if aggregates are seen */ u8 isCheck; /* True if resolving names in a CHECK constraint */ int nDepth; /* Depth of subquery recursion. 1 for no recursion */ AggInfo *pAggInfo; /* Information about aggregates at this level */ NameContext *pNext; /* Next outer name context. NULL for outermost */};/*** An instance of the following structure contains all information** needed to generate code for a single SELECT statement.**** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0.** If there is a LIMIT clause, the parser sets nLimit to the value of the** limit and nOffset to the value of the offset (or 0 if there is not** offset). But later on, nLimit and nOffset become the memory locations** in the VDBE that record the limit and offset counters.**** addrOpenEphm[] entries contain the address of OP_OpenEphemeral opcodes.** These addresses must be stored so that we can go back and fill in** the P3_KEYINFO and P2 parameters later. Neither the KeyInfo nor** the number of columns in P2 can be computed at the same time** as the OP_OpenEphm instruction is coded because not** enough information about the compound query is known at that point.** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences** for the result set. The KeyInfo for addrOpenTran[2] contains collating** sequences for the ORDER BY clause.*/struct Select { ExprList *pEList; /* The fields of the result */ u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */ u8 isDistinct; /* True if the DISTINCT keyword is present */ u8 isResolved; /* True once sqlite3SelectResolve() has run. */ u8 isAgg; /* True if this is an aggregate query */ u8 usesEphm; /* True if uses an OpenEphemeral opcode */ u8 disallowOrderBy; /* Do not allow an ORDER BY to be attached if TRUE */ char affinity; /* MakeRecord with this affinity for SRT_Set */ SrcList *pSrc; /* The FROM clause */ Expr *pWhere; /* The WHERE clause */ ExprList *pGroupBy; /* The GROUP BY clause */ Expr *pHaving; /* The HAVING clause */ ExprList *pOrderBy; /* The ORDER BY clause */ Select *pPrior; /* Prior select in a compound select statement */ Select *pRightmost; /* Right-most select in a compound select statement */ Expr *pLimit; /* LIMIT expression. NULL means not used. */ Expr *pOffset; /* OFFSET expression. NULL means not used. */ int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */ int addrOpenEphm[3]; /* OP_OpenEphem opcodes related to this select */};/*** The results of a select can be distributed in several ways.*/#define SRT_Union 1 /* Store result as keys in an index */#define SRT_Except 2 /* Remove result from a UNION index */#define SRT_Discard 3 /* Do not save the results anywhere *//* The ORDER BY clause is ignored for all of the above */#define IgnorableOrderby(X) (X<=SRT_Discard)#define SRT_Callback 4 /* Invoke a callback with each row of result */#define SRT_Mem 5 /* Store result in a memory cell */#define SRT_Set 6 /* Store non-null results as keys in an index */#define SRT_Table 7 /* Store result as data with an automatic rowid */#define SRT_EphemTab 8 /* Create transient tab and store like SRT_Table */#define SRT_Subroutine 9 /* Call a subroutine to handle results */#define SRT_Exists 10 /* Store 1 if the result is not empty *//*** An SQL parser context. A copy of this structure is passed through** the parser and down into all the parser action routine in order to** carry around information that is global to the entire parse.**** The structure is divided into two parts. When the parser and code** generate call themselves recursively, the first part of the structure** is constant but the second part is reset at the beginning and end of** each recursion.**** The nTableLock and aTableLock variables are only used if the shared-cache ** feature is enabled (if sqlite3Tsd()->useSharedData is true). They are** used to store the set of table-locks required by the statement being** compiled. Function sqlite3TableLock() is used to add entries to the** list.*/struct Parse { sqlite3 *db; /* The main database structure */ int rc; /* Return code from execution */ char *zErrMsg; /* An error message */ Vdbe *pVdbe; /* An engine for executing database bytecode */ u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */ u8 nameClash; /* A permanent table name clashes with temp table name */ u8 checkSchema; /* Causes schema cookie check after an error */ u8 nested; /* Number of nested calls to the parser/code generator */ u8 parseError; /* True after a parsing error. Ticket #1794 */ int nErr; /* Number of errors seen */ int nTab; /* Number of previously allocated VDBE cursors */ int nMem; /* Number of memory cells used so far */ int nSet; /* Number of sets used so far */ int ckOffset; /* Stack offset to data used by CHECK constraints */ u32 writeMask; /* Start a write transaction on these databases */ u32 cookieMask; /* Bitmask of schema verified databases */ int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */ int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */#ifndef SQLITE_OMIT_SHARED_CACHE int nTableLock; /* Number of locks in aTableLock */ TableLock *aTableLock; /* Required table locks for shared-cache mode */#endif /* Above is constant between recursions. Below is reset before and after ** each recursion */ int nVar; /* Number of '?' variables seen in the SQL so far */ int nVarExpr; /* Number of used slots in apVarExpr[] */ int nVarExprAlloc; /* Number of allocated slots in apVarExpr[] */ Expr **apVarExpr; /* Pointers to :aaa and $aaaa wildcard expressions */ u8 explain; /* True if the EXPLAIN flag is found on the query */ Token sErrToken; /* The token at which the error occurred */ Token sNameToken; /* Token with unqualified schema object name */ Token sLastToken; /* The last token parsed */ const char *zSql; /* All SQL text */ const char *zTail; /* All SQL text past the last semicolon parsed */ Table *pNewTable; /* A table being constructed by CREATE TABLE */ Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */ TriggerStack *trigStack; /* Trigger actions being coded */ const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */#ifndef SQLITE_OMIT_VIRTUALTABLE Token sArg; /* Complete text of a module argument */ u8 declareVtab; /* True if inside sqlite3_declare_vtab() */ Table *pVirtualLock; /* Require virtual table lock on this table */#endif#if SQLITE_MAX_EXPR_DEPTH>0 int nHeight; /* Expression tree height of current sub-select */#endif};#ifdef SQLITE_OMIT_VIRTUALTABLE #define IN_DECLARE_VTAB 0#else #define IN_DECLARE_VTAB (pParse->declareVtab)#endif/*** An instance of the following structure can be declared on a stack and used** to save the Parse.zAuthContext value so that it can be restored later.*/struct AuthContext { const char *zAuthContext; /* Put saved Parse.zAuthContext here */ Parse *pParse; /* The Parse structure */};/*** Bitfield flags for P2 value in OP_Insert and OP_Delete*/#define OPFLAG_NCHANGE 1 /* Set to update db->nChange */#define OPFLAG_LASTROWID 2 /* Set to update db->lastRowid */#define OPFLAG_ISUPDATE 4 /* This OP_Insert is an sql UPDATE */#define OPFLAG_APPEND 8 /* This is likely to be an append *//* * Each trigger present in the database schema is stored as an instance of * struct Trigger. * * Pointers to instances of struct Trigger are stored in two ways. * 1. In the "trigHash" hash table (part of the sqlite3* that represents the * database). This allows Trigger structures to be retrieved by name. * 2. All triggers associated with a single table form a linked list, using the * pNext member of struct Trigger. A pointer to the first element of the * linked list is stored as the "pTrigger" member of the associated * struct Table. * * The "step_list" member points to the first element of a linked list * containing the SQL statements specified as the trigger program. */struct Trigger { char *name; /* The name of the trigger */ char *table; /* The table or view to which the trigger applies */ u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */ u8 tr_tm; /* One of TRIGGER_BEFORE, TRIGGER_AFTER */ Expr *pWhen; /* The WHEN clause of the expresion (may be NULL) */ IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger, the <column-list> is stored here */ Token nameToken; /* Token containing zName. Use during parsing only */ Schema *pSchema; /* Schema containing the trigger */ Schema *pTabSchema; /* Schema containing the table */ TriggerStep *step_list; /* Link list of trigger program steps */ Trigger *pNext; /* Next trigger associated with the table */};/*** A trigger is either a BEFORE or an AFTER trigger. The following constants** determine which. **** If there are multiple triggers, you might of some BEFORE and some AFTER.** In that cases, the constants below can be ORed together.*/#define TRIGGER_BEFORE 1#define TRIGGER_AFTER 2/* * An instance of struct TriggerStep is used to store a single SQL statement * that is a part of a trigger-program. * * Instances of struct TriggerStep are stored in a singly linked list (linked * using the "pNext" member) referenced by the "step_list" member of the * associated struct Trigger instance. The first element of the linked list is * the first step of the trigger-program. * * The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or * "SELECT" statement. The meanings of the other members is determined by the * value of "op" as follows: * * (op == TK_INSERT) * orconf -> stores the ON CONFLICT algorithm * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then * this s
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -