📄 sqliteint.h
字号:
#define SQLITE_AFF_MASK 0x67/*** Additional bit values that can be ORed with an affinity without** changing the affinity.*/#define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */#define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump *//*** Each SQL table is represented in memory by an instance of the** following structure.**** Table.zName is the name of the table. The case of the original** CREATE TABLE statement is stored, but case is not significant for** comparisons.**** Table.nCol is the number of columns in this table. Table.aCol is a** pointer to an array of Column structures, one for each column.**** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of** the column that is that key. Otherwise Table.iPKey is negative. Note** that the datatype of the PRIMARY KEY must be INTEGER for this field to** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid** is generated for each row of the table. TF_HasPrimaryKey is set if** the table has any PRIMARY KEY, INTEGER or otherwise.**** Table.tnum is the page number for the root BTree page of the table in the** database file. If Table.iDb is the index of the database table backend** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that** holds temporary tables and indices. If TF_Ephemeral is set** then the table is stored in a file that is automatically deleted** when the VDBE cursor to the table is closed. In this case Table.tnum ** 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 { sqlite3 *db; /* Associated database connection. Might be NULL. */ char *zName; /* Name of the table or view */ int iPKey; /* If not negative, use aCol[iPKey] as the primary key */ int nCol; /* Number of columns in this table */ Column *aCol; /* Information about each column */ 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. */ u16 nRef; /* Number of pointers to this Table */ u8 tabFlags; /* Mask of TF_* values */ u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ 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_CHECK Expr *pCheck; /* The AND of all CHECK constraints */#endif#ifndef SQLITE_OMIT_ALTERTABLE int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */#endif#ifndef SQLITE_OMIT_VIRTUALTABLE Module *pMod; /* Pointer to the implementation of the module */ sqlite3_vtab *pVtab; /* Pointer to the module instance */ int nModuleArg; /* Number of arguments to the module */ char **azModuleArg; /* Text of all module args. [0] is module name */#endif Schema *pSchema; /* Schema that contains this table */};/*** Allowed values for Tabe.tabFlags.*/#define TF_Readonly 0x01 /* Read-only system table */#define TF_Ephemeral 0x02 /* An emphermal table */#define TF_HasPrimaryKey 0x04 /* Table has a primary key */#define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */#define TF_Virtual 0x10 /* Is a virtual table */#define TF_NeedMetadata 0x20 /* aCol[].zType and aCol[].pColl missing *//*** Test to see whether or not a table is a virtual table. This is** done as a macro so that it will be optimized out when virtual** table support is omitted from the build.*/#ifndef SQLITE_OMIT_VIRTUALTABLE# define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0)# define IsHiddenColumn(X) ((X)->isHidden)#else# define IsVirtual(X) 0# define IsHiddenColumn(X) 0#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 constraint** 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.*/struct KeyInfo { sqlite3 *db; /* The database connection */ u8 enc; /* Text encoding - one of the TEXT_Utf* values */ u16 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 */};/*** An instance of the following structure holds information about a** single index record that has already been parsed out into individual** values.**** A record is an object that contains one or more fields of data.** Records are used to store the content of a table row and to store** the key of an index. A blob encoding of a record is created by** the OP_MakeRecord opcode of the VDBE and is disassemblied by the** OP_Column opcode.**** This structure holds a record that has already been disassembled** into its constitutent fields.*/struct UnpackedRecord { KeyInfo *pKeyInfo; /* Collation and sort-order information */ u16 nField; /* Number of entries in apMem[] */ u16 flags; /* Boolean settings. UNPACKED_... below */ Mem *aMem; /* Values */};/*** Allowed values of UnpackedRecord.flags*/#define UNPACKED_NEED_FREE 0x0001 /* Memory is from sqlite3Malloc() */#define UNPACKED_NEED_DESTROY 0x0002 /* apMem[]s should all be destroyed */#define UNPACKED_IGNORE_ROWID 0x0004 /* Ignore trailing rowid on key1 */#define UNPACKED_INCRKEY 0x0008 /* Make this key an epsilon larger */#define UNPACKED_PREFIX_MATCH 0x0010 /* A prefix match is considered OK *//*** 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 */ unsigned *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */ 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) */ char *zColAff; /* String defining the affinity of each column */ Index *pNext; /* The next index associated with the same table */ Schema *pSchema; /* Schema containing this index */ u8 *aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */ char **azColl; /* Array of collation sequence names for index */};/*** 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 */};/*** An instance of this structure contains information needed to generate** code for a SELECT that contains aggregate functions.**** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a** pointer to this structure. The Expr.iColumn field is the index in** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate** code for that node.**** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the** original Select structure that describes the SELECT statement. These** fields do not need to be freed when deallocating the AggInfo structure.*/struct AggInfo { u8 directMode; /* Direct rendering mode means take data directly ** from source tables rather than from accumulators */ u8 useSortingIdx; /* In direct mode, reference the sorting index rather ** than the source table */ int sortingIdx; /* Cursor number of the sorting index */ ExprList *pGroupBy; /* The group by clause */ int nSortingColumn; /* Number of columns in the sorting index */ struct AggInfo_col { /* For each column used in source tables */ Table *pTab; /* Source table */ int iTable; /* Cursor number of the source table */ int iColumn; /* Column number within the source table */ int iSorterColumn; /* Column number in the sorting index */ int iMem; /* Memory location that acts as accumulator */ Expr *pExpr; /* The original expression */ } *aCol; int nColumn; /* Number of used entries in aCol[] */ int nColumnAlloc; /* Number of slots allocated for aCol[] */ int nAccumulator; /* Number of columns that show through to the output.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -