📄 sqliteint.h
字号:
** refers VDBE cursor number that holds the table open, not to the root** page number. Transient tables are used to hold the results of a** sub-query that appears instead of a real table name in the FROM clause ** of a SELECT statement.*/struct Table { char *zName; /* Name of the table */ int nCol; /* Number of columns in this table */ Column *aCol; /* Information about each column */ int iPKey; /* If not less then 0, use aCol[iPKey] as the primary key */ Index *pIndex; /* List of SQL indexes on this table. */ int tnum; /* Root BTree node for this table (see note above) */ Select *pSelect; /* NULL for tables. Points to definition if a view. */ u8 readOnly; /* True if this table should not be written by the user */ u8 iDb; /* Index into sqlite.aDb[] of the backend for this table */ u8 isTransient; /* True if automatically deleted when VDBE finishes */ u8 hasPrimKey; /* True if there exists a primary key */ u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ u8 autoInc; /* True if the integer primary key is autoincrement */ int nRef; /* Number of pointers to this Table */ Trigger *pTrigger; /* List of SQL triggers on this table */ FKey *pFKey; /* Linked list of all foreign keys in this table */ char *zColAff; /* String defining the affinity of each column */#ifndef SQLITE_OMIT_ALTERTABLE int addColOffset; /* Offset in CREATE TABLE statement to add a new column */#endif};/*** Each foreign key constraint is an instance of the following structure.**** A foreign key is associated with two tables. The "from" table is** the table that contains the REFERENCES clause that creates the foreign** key. The "to" table is the table that is named in the REFERENCES clause.** Consider this example:**** CREATE TABLE ex1(** a INTEGER PRIMARY KEY,** b INTEGER CONSTRAINT fk1 REFERENCES ex2(x)** );**** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2".**** Each REFERENCES clause generates an instance of the following structure** which is attached to the from-table. The to-table need not exist when** the from-table is created. The existance of the to-table is not checked** until an attempt is made to insert data into the from-table.**** The sqlite.aFKey hash table stores pointers to this structure** given the name of a to-table. For each to-table, all foreign keys** associated with that table are on a linked list using the FKey.pNextTo** field.*/struct FKey { Table *pFrom; /* The table that constains the REFERENCES clause */ FKey *pNextFrom; /* Next foreign key in pFrom */ char *zTo; /* Name of table that the key points to */ FKey *pNextTo; /* Next foreign key that points to zTo */ int nCol; /* Number of columns in this key */ struct sColMap { /* Mapping of columns in pFrom to columns in zTo */ int iFrom; /* Index of column in pFrom */ char *zCol; /* Name of column in zTo. If 0 use PRIMARY KEY */ } *aCol; /* One entry for each of nCol column s */ u8 isDeferred; /* True if constraint checking is deferred till COMMIT */ u8 updateConf; /* How to resolve conflicts that occur on UPDATE */ u8 deleteConf; /* How to resolve conflicts that occur on DELETE */ u8 insertConf; /* How to resolve conflicts that occur on INSERT */};/*** SQLite supports many different ways to resolve a contraint** error. ROLLBACK processing means that a constraint violation** causes the operation in process to fail and for the current transaction** to be rolled back. ABORT processing means the operation in process** fails and any prior changes from that one operation are backed out,** but the transaction is not rolled back. FAIL processing means that** the operation in progress stops and returns an error code. But prior** changes due to the same operation are not backed out and no rollback** occurs. IGNORE means that the particular row that caused the constraint** error is not inserted or updated. Processing continues and no error** is returned. REPLACE means that preexisting database rows that caused** a UNIQUE constraint violation are removed so that the new insert or** update can proceed. Processing continues and no error is reported.**** RESTRICT, SETNULL, and CASCADE actions apply only to foreign keys.** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the** same as ROLLBACK for DEFERRED keys. SETNULL means that the foreign** key is set to NULL. CASCADE means that a DELETE or UPDATE of the** referenced table row is propagated into the row that holds the** foreign key.** ** The following symbolic values are used to record which type** of action to take.*/#define OE_None 0 /* There is no constraint to check */#define OE_Rollback 1 /* Fail the operation and rollback the transaction */#define OE_Abort 2 /* Back out changes but do no rollback transaction */#define OE_Fail 3 /* Stop the operation but leave all prior changes */#define OE_Ignore 4 /* Ignore the error. Do not do the INSERT or UPDATE */#define OE_Replace 5 /* Delete existing record, then do INSERT or UPDATE */#define OE_Restrict 6 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */#define OE_SetNull 7 /* Set the foreign key value to NULL */#define OE_SetDflt 8 /* Set the foreign key value to its default */#define OE_Cascade 9 /* Cascade the changes */#define OE_Default 99 /* Do whatever the default action is *//*** An instance of the following structure is passed as the first** argument to sqlite3VdbeKeyCompare and is used to control the ** comparison of the two index keys.**** If the KeyInfo.incrKey value is true and the comparison would** otherwise be equal, then return a result as if the second key** were larger.*/struct KeyInfo { u8 enc; /* Text encoding - one of the TEXT_Utf* values */ u8 incrKey; /* Increase 2nd key by epsilon before comparison */ int nField; /* Number of entries in aColl[] */ u8 *aSortOrder; /* If defined an aSortOrder[i] is true, sort DESC */ CollSeq *aColl[1]; /* Collating sequence for each term of the key */};/*** Each SQL index is represented in memory by an** instance of the following structure.**** The columns of the table that are to be indexed are described** by the aiColumn[] field of this structure. For example, suppose** we have the following table and index:**** CREATE TABLE Ex1(c1 int, c2 int, c3 text);** CREATE INDEX Ex2 ON Ex1(c3,c1);**** In the Table structure describing Ex1, nCol==3 because there are** three columns in the table. In the Index structure describing** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed.** The value of aiColumn is {2, 0}. aiColumn[0]==2 because the ** first column to be indexed (c3) has an index of 2 in Ex1.aCol[].** The second column to be indexed (c1) has an index of 0 in** Ex1.aCol[], hence Ex2.aiColumn[1]==0.**** The Index.onError field determines whether or not the indexed columns** must be unique and what to do if they are not. When Index.onError=OE_None,** it means this is not a unique index. Otherwise it is a unique index** and the value of Index.onError indicate the which conflict resolution ** algorithm to employ whenever an attempt is made to insert a non-unique** element.*/struct Index { char *zName; /* Name of this index */ int nColumn; /* Number of columns in the table used by this index */ int *aiColumn; /* Which columns are used by this index. 1st is 0 */ Table *pTable; /* The SQL table being indexed */ int tnum; /* Page containing root of this index in database file */ u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */ u8 iDb; /* Index in sqlite.aDb[] of where this index is stored */ char *zColAff; /* String defining the affinity of each column */ Index *pNext; /* The next index associated with the same table */ KeyInfo keyInfo; /* Info on how to order keys. MUST BE LAST */};/*** Each token coming out of the lexer is an instance of** this structure. Tokens are also used as part of an expression.**** Note if Token.z==0 then Token.dyn and Token.n are undefined and** may contain random values. Do not make any assuptions about Token.dyn** and Token.n when Token.z==0.*/struct Token { const unsigned char *z; /* Text of the token. Not NULL-terminated! */ unsigned dyn : 1; /* True for malloced memory, false for static */ unsigned n : 31; /* Number of characters in this token */};/*** Each node of an expression in the parse tree is an instance** of this structure.**** Expr.op is the opcode. The integer parser token codes are reused** as opcodes here. For example, the parser defines TK_GE to be an integer** code representing the ">=" operator. This same integer code is reused** to represent the greater-than-or-equal-to operator in the expression** tree.**** Expr.pRight and Expr.pLeft are subexpressions. Expr.pList is a list** of argument if the expression is a function.**** Expr.token is the operator token for this node. For some expressions** that have subexpressions, Expr.token can be the complete text that gave** rise to the Expr. In the latter case, the token is marked as being** a compound token.**** An expression of the form ID or ID.ID refers to a column in a table.** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is** the integer cursor number of a VDBE cursor pointing to that table and** Expr.iColumn is the column number for the specific column. If the** expression is used as a result in an aggregate SELECT, then the** value is also stored in the Expr.iAgg column in the aggregate so that** it can be accessed after all aggregates are computed.**** If the expression is a function, the Expr.iTable is an integer code** representing which function. If the expression is an unbound variable** marker (a question mark character '?' in the original SQL) then the** Expr.iTable holds the index number for that variable.**** If the expression is a subquery then Expr.iColumn holds an integer** register number containing the result of the subquery. If the** subquery gives a constant result, then iTable is -1. If the subquery** gives a different answer at different times during statement processing** then iTable is the address of a subroutine that computes the subquery.**** The Expr.pSelect field points to a SELECT statement. The SELECT might** be the right operand of an IN operator. Or, if a scalar SELECT appears** in an expression the opcode is TK_SELECT and Expr.pSelect is the only** operand.**** If the Expr is of type OP_Column, and the table it is selecting from** is a disk table or the "old.*" pseudo-table, then pTab points to the** corresponding table definition.*/struct Expr { u8 op; /* Operation performed by this node */ char affinity; /* The affinity of the column or 0 if not a column */ u8 iDb; /* Database referenced by this expression */ u8 flags; /* Various flags. See below */ CollSeq *pColl; /* The collation type of the column or 0 */ Expr *pLeft, *pRight; /* Left and right subnodes */ ExprList *pList; /* A list of expressions used as function arguments ** or in "<expr> IN (<expr-list)" */ Token token; /* An operand token */ Token span; /* Complete text of the expression */ int iTable, iColumn; /* When op==TK_COLUMN, then this expr node means the ** iColumn-th field of the iTable-th table. */ int iAgg; /* When op==TK_COLUMN and pParse->fillAgg==FALSE, pull ** result from the iAgg-th element of the aggregator */ int iAggCtx; /* The value to pass as P1 of OP_AggGet. */ Select *pSelect; /* When the expression is a sub-select. Also the ** right side of "<expr> IN (<select>)" */ Table *pTab; /* Table for OP_Column expressions. */};/*** The following are the meanings of bits in the Expr.flags field.*/#define EP_FromJoin 0x0001 /* Originated in ON or USING clause of a join */#define EP_Agg 0x0002 /* Contains one or more aggregate functions */#define EP_Resolved 0x0004 /* IDs have been resolved to COLUMNs */#define EP_Error 0x0008 /* Expression contains one or more errors */#define EP_Not 0x0010 /* Operator preceeded by NOT */#define EP_VarSelect 0x0020 /* pSelect is correlated, not constant *//*** These macros can be used to test, set, or clear bits in the ** Expr.flags field.*/#define ExprHasProperty(E,P) (((E)->flags&(P))==(P))#define ExprHasAnyProperty(E,P) (((E)->flags&(P))!=0)#define ExprSetProperty(E,P) (E)->flags|=(P)#define ExprClearProperty(E,P) (E)->flags&=~(P)/*** A list of expressions. Each expression may optionally have a** name. An expr/name combination can be used in several ways, such** as the list of "expr AS ID" fields following a "SELECT" or in the** list of "ID = expr" items in an UPDATE. A list of expressions can** also be used as the argument to a function, in which case the a.zName** field is not used.*/struct ExprList { int nExpr; /* Number of expressions on the list */ int nAlloc; /* Number of entries allocated below */ struct ExprList_item { Expr *pExpr; /* The list of expressions */ char *zName; /* Token associated with this expression */ u8 sortOrder; /* 1 for DESC or 0 for ASC */ u8 isAgg; /* True if this is an aggregate like count(*) */ u8 done; /* A flag to indicate when processing is finished */ } *a; /* One entry for each expression */};/*** An instance of this structure can hold a simple list of identifiers,** such as the list "a,b,c" in the following statements:**** INSERT INTO t(a,b,c) VALUES ...;** CREATE INDEX idx ON t(a,b,c);** CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...;**** The IdList.a.idx field is used when the IdList represents the list of
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -