📄 sqliteint.h
字号:
** the number of columns in P2 can be computed at the same time** as the OP_OpenVirtual instruction is coded because not** enough information about the compound query is known at that point.** The KeyInfo for addrOpenVirt[0] and [1] contains collating sequences** for the result set. The KeyInfo for addrOpenVirt[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 usesVirt; /* True if uses an OpenVirtual opcode */ u8 disallowOrderBy; /* Do not allow an ORDER BY to be attached if TRUE */ 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 addrOpenVirt[3]; /* OP_OpenVirtual 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_VirtualTab 8 /* Create virtual table 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 */ 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[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 */};/*** 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 *//* * 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 */ int foreach; /* One of TK_ROW or TK_STATEMENT */ 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 stores a pointer to the SELECT statement. Otherwise NULL. * target -> A token holding the name of the table to insert into. * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then * this stores values to be inserted. Otherwise NULL. * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ... * statement, then this stores the column-names to be * inserted into. * * (op == TK_DELETE) * target -> A token holding the name of the table to delete from. * pWhere -> The WHERE clause of the DELETE statement if one is specified. * Otherwise NULL. * * (op == TK_UPDATE) * target -> A token holding the name of the table to update rows of. * pWhere -> The WHERE clause of the UPDATE statement if one is specified. * Otherwise NULL. * pExprList -> A list of the columns to update and the expressions to update * them to. See sqlite3Update() documentation of "pChanges" * argument. * */struct TriggerStep { int op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */ int orconf; /* OE_Rollback etc. */ Trigger *pTrig; /* The trigger that this step is a part of */ Select *pSelect; /* Valid for SELECT and sometimes INSERT steps (when pExprList == 0) */ Token target; /* Valid for DELETE, UPDATE, INSERT steps */ Expr *pWhere; /* Valid for DELETE, UPDATE steps */ ExprList *pExprList; /* Valid for UPDATE statements and sometimes INSERT steps (when pSelect == 0) */ IdList *pIdList; /* Valid for INSERT statements only */ TriggerStep *pNext; /* Next in the link-list */ TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */};/* * An instance of struct TriggerStack stores information required during code * generation of a single trigger program. While the trigger program is being * coded, its associated TriggerStack instance is pointed to by the * "pTriggerStack" member of the Parse structure. * * The pTab member points to the table that triggers are being coded on. The * newIdx member contains the index of the vdbe cursor that points at the temp * table that stores the new.* references. If new.* references are not valid * for the trigger being coded (for example an ON DELETE trigger), then newIdx * is set to -1. The oldIdx member is analogous to newIdx, for old.* references. * * The ON CONFLICT policy to be used for the trigger program steps is stored * as the orconf member. If this is OE_Default, then the ON CONFLICT clause * specified for individual triggers steps is used. * * struct TriggerStack has a "pNext" member, to allow linked lists to be * constructed. When coding nested triggers (triggers fired by other triggers) * each nested trigger stores its parent trigger's TriggerStack as the "pNext" * pointer. Once the nested trigger has been coded, the pNext value is restored * to the pTriggerStack member of the Parse stucture and coding of the parent * trigger continues. * * Before a nested trigger is coded, the linked list pointed to by the * pTriggerStack is scanned to ensure that the trigger is not about to be coded * recursively. If this condition is detected, the nested trigger is not coded. */struct TriggerStack { Table *pTab; /* Table that triggers are currently being coded on */ int newIdx; /* Index of vdbe cursor to "new" temp table */ int oldIdx; /* Index of vdbe cursor to "old" temp table */ int orconf; /* Current orconf policy */ int ignoreJump; /* where to jump to for a RAISE(IGNORE) */ Trigger *pTrigger; /* The trigger currently being coded */ TriggerStack *pNext; /* Next trigger down on the trigger stack */};/*** The following structure contains information used by the sqliteFix...** routines as they walk the parse tree to make database references** explicit. */typedef struct DbFixer DbFixer;struct DbFixer { Parse *pParse; /* The parsing context. Error messages written here */ const char *zDb; /* Make sure all objects are contained in this database */ const char *zType; /* Type of the container - used for error messages */ const Token *pName; /* Name of the container - used for error messages */};/*** A pointer to this structure is used to communicate information** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback.*/typedef struct { sqlite3 *db; /* The database being initialized */ char **pzErrMsg; /* Error message stored here */} InitData;/* * This global flag is set for performance testing of triggers. When it is set * SQLite will perform the overhead of building new and old trigger references * even when no triggers exist */extern int sqlite3_always_code_trigger_setup;/*** The SQLITE_CORRUPT_BKPT macro can be either a constant (for production** builds) or a function call (for debugging). If it is a function call,** it allows the operator to set a breakpoint at the spot where database** corruption is first detected.*/#ifdef SQLITE_DEBUG extern int sqlite3Corrupt(void);# define SQLITE_CORRUPT_BKPT sqlite3Corrupt()#else# define SQLITE_CORRUP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -