2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A** The author disclaims copyright to this source code. In place of 2N/A** a legal notice, here is a blessing: 2N/A** May you do good and not evil. 2N/A** May you find forgiveness for yourself and forgive others. 2N/A** May you share freely, never taking more than you give. 2N/A************************************************************************* 2N/A** Internal interface definitions for SQLite. 2N/A** The maximum number of in-memory pages to use for the main database 2N/A** table and for temporary tables. 2N/A** If the following macro is set to 1, then NULL values are considered 2N/A** distinct for the SELECT DISTINCT statement and for UNION or EXCEPT 2N/A** compound queries. No other SQL database engine (among those tested) 2N/A** works this way except for OCELOT. But the SQL92 spec implies that 2N/A** this is how things should work. 2N/A** If the following macro is set to 0, then NULLs are indistinct for 2N/A** SELECT DISTINCT and for UNION. 2N/A** If the following macro is set to 1, then NULL values are considered 2N/A** distinct when determining whether or not two entries are the same 2N/A** in a UNIQUE index. This is the way PostgreSQL, Oracle, DB2, MySQL, 2N/A** OCELOT, and Firebird all work. The SQL92 spec explicitly says this 2N/A** is the way things are suppose to work. 2N/A** If the following macro is set to 0, the NULLs are indistinct for 2N/A** a UNIQUE index. In this mode, you can only have a single NULL entry 2N/A** for a column declared UNIQUE. This is the way Informix and SQL Server 2N/A** The maximum number of attached databases. This must be at least 2 2N/A** in order to support the main database file (0) and the file used to 2N/A** hold temporary tables (1). And it must be less than 256 because 2N/A** an unsigned character is used to stored the database index. 2N/A** The next macro is used to determine where TEMP tables and indices 2N/A** are stored. Possible values: 2N/A** 0 Always use a temporary files 2N/A** 1 Use a file unless overridden by "PRAGMA temp_store" 2N/A** 2 Use memory unless overridden by "PRAGMA temp_store" 2N/A** 3 Always use memory 2N/A** When building SQLite for embedded systems where memory is scarce, 2N/A** you can define one or more of the following macros to omit extra 2N/A** features of the library and thus keep the size of the library to 2N/A/* #define SQLITE_OMIT_AUTHORIZATION 1 */ 2N/A/* #define SQLITE_OMIT_INMEMORYDB 1 */ 2N/A/* #define SQLITE_OMIT_VACUUM 1 */ 2N/A/* #define SQLITE_OMIT_DATETIME_FUNCS 1 */ 2N/A/* #define SQLITE_OMIT_PROGRESS_CALLBACK 1 */ 2N/A** Integers of known sizes. These typedefs might change for architectures 2N/A** where the sizes very. Preprocessor macros are available so that the 2N/A** types can be conveniently redefined at compile-type. Like this: 2N/A** cc '-DUINTPTR_TYPE=long long int' ... 2N/A** Defer sourcing vdbe.h until after the "u8" typedef is defined. 2N/A** Most C compilers these days recognize "long double", don't they? 2N/A** Just in case we encounter one that does not, we will create a macro 2N/A** for long double so that it can be easily changed to just "double". 2N/A** This macro casts a pointer to an integer. Useful for doing 2N/A** pointer arithmetic. 2N/A** The maximum number of bytes of data that can be put into a single 2N/A** row of a single table. The upper bound on this limit is 16777215 2N/A** bytes (or 16MB-1). We have arbitrarily set the limit to just 1MB 2N/A** here because the overflow page chain is inefficient for really big 2N/A** records and we want to discourage people from thinking that 2N/A** multi-megabyte records are OK. If your needs are different, you can 2N/A** change this define and recompile to increase or decrease the record 2N/A** The 16777198 is computed as follows: 238 bytes of payload on the 2N/A** original pages plus 16448 overflow pages each holding 1020 bytes of 2N/A/* #define MAX_BYTES_PER_ROW 16777198 */ 2N/A** If memory allocation problems are found, recompile with 2N/A** to enable some sanity checking on malloc() and free(). To 2N/A** check for memory leaks, recompile with 2N/A** and a line of text will be written to standard error for 2N/A** each malloc() and free(). This output can be analyzed 2N/A** by an AWK script to determine if there are any leaks. 2N/A** This variable gets set if malloc() ever fails. After it gets set, 2N/A** the SQLite library shuts down permanently. 2N/A** The following global variables are used for testing and debugging 2N/A** only. They only work if MEMORY_DEBUG is defined. 2N/A** Name of the master database table. The master database table 2N/A** is a special table that holds the names and attributes of all 2N/A** user tables and indices. 2N/A** The name of the schema table. 2N/A** A convenience macro that returns the number of elements in 2N/A** Forward references to structures 2N/A** Each database file to be accessed by the system is an instance 2N/A** of the following structure. There are normally two of these structures 2N/A** in the sqlite.aDb[] array. aDb[0] is the main database file and 2N/A** aDb[1] is the database file used to hold temporary tables. Additional 2N/A** databases may be attached. 2N/A char *
zName;
/* Name of this database */ 2N/A Btree *
pBt;
/* The B*Tree structure for this database file */ 2N/A u8 inTrans;
/* 0: not writable. 1: Transaction. 2: Checkpoint */ 2N/A void *
pAux;
/* Auxiliary data. Usually NULL */ 2N/A** These macros can be used to test, set, or clear bits in the 2N/A** Allowed values for the DB.flags field. 2N/A** The DB_Locked flag is set when the first OP_Transaction or OP_Checkpoint 2N/A** opcode is emitted for a database. This prevents multiple occurances 2N/A** of those opcodes for the same database in the same program. Similarly, 2N/A** the DB_Cookie flag is set when the OP_VerifyCookie opcode is emitted, 2N/A** and prevents duplicate OP_VerifyCookies from taking up space and slowing 2N/A** The DB_SchemaLoaded flag is set after the database schema has been 2N/A** read into internal hash tables. 2N/A** DB_UnresetViews means that one or more views have column names that 2N/A** have been filled out. If the schema changes, these column names might 2N/A** changes and so the view will need to be reset. 2N/A#
define DB_Locked 0x0001 /* OP_Transaction opcode has been emitted */ 2N/A#
define DB_Cookie 0x0002 /* OP_VerifyCookie opcode has been emiited */ 2N/A** Each database is an instance of the following structure. 2N/A** The sqlite.file_format is initialized by the database file 2N/A** and helps determines how the data in the database file is 2N/A** represented. This field allows newer versions of the library 2N/A** to read and write older databases. The various file formats 2N/A** file_format==1 Version 2.1.0. 2N/A** file_format==2 Version 2.2.0. Add support for INTEGER PRIMARY KEY. 2N/A** file_format==3 Version 2.6.0. Fix empty-string index bug. 2N/A** file_format==4 Version 2.7.0. Add support for separate numeric and 2N/A** The sqlite.temp_store determines where temporary database files 2N/A** are stored. If 1, then a file is created to hold those tables. If 2N/A** 2, then they are held in memory. 0 means use the default value in 2N/A** the TEMP_STORE macro. 2N/A** The sqlite.lastRowid records the last insert rowid generated by an 2N/A** insert statement. Inserts on views do not affect its value. Each 2N/A** trigger has its own context, so that lastRowid can be updated inside 2N/A** triggers as usual. The previous value will be restored once the trigger 2N/A** exits. Upon entering a before or instead of trigger, lastRowid is no 2N/A** longer (since after version 2.8.12) reset to -1. 2N/A** The sqlite.nChange does not count changes within triggers and keeps no 2N/A** context. It is reset at start of sqlite_exec. 2N/A** The sqlite.lsChange represents the number of changes made by the last 2N/A** insert, update, or delete statement. It remains constant throughout the 2N/A** length of a statement and is then updated by OP_SetCounts. It keeps a 2N/A** context stack just like lastRowid so that the count of changes 2N/A** within a trigger is not seen outside the trigger. Changes to views do not 2N/A** affect the value of lsChange. 2N/A** The sqlite.csChange keeps track of the number of current changes (since 2N/A** the last statement) and is used to update sqlite_lsChange. 2N/A int nDb;
/* Number of backends currently in use */ 2N/A int flags;
/* Miscellanous flags. See below */ 2N/A int nTable;
/* Number of tables in the database */ 2N/A void *
pBusyArg;
/* 1st Argument to the busy callback */ 2N/A int lastRowid;
/* ROWID of most recent insert (see above) */ 2N/A int magic;
/* Magic number for detect library misuse */ 2N/A int nChange;
/* Number of rows changed (see above) */ 2N/A int lsChange;
/* Last statement change count (see above) */ 2N/A int csChange;
/* Current statement change count (see above) */ 2N/A int iDb;
/* When back is being initialized */ 2N/A int newTnum;
/* Rootpage of table being initialized */ 2N/A u8 busy;
/* TRUE if currently initializing */ 2N/A void (*
xTrace)(
void*,
const char*);
/* Trace function */ 2N/A int (*
xAuth)(
void*,
int,
const char*,
const char*,
const char*,
const char*);
2N/A /* Access authorization function */ 2N/A void *
pAuthArg;
/* 1st argument to the access auth function */ 2N/A** Possible values for the sqlite.flags and or Db.flags fields. 2N/A** On sqlite.flags, the SQLITE_InTrans value means that we have 2N/A** executed a BEGIN. On Db.flags, SQLITE_InTrans means a statement 2N/A** transaction is active on that particular database file. 2N/A /* DELETE, or UPDATE and return */ 2N/A /* the count using a callback. */ 2N/A /* result set is empty */ 2N/A /* in 4th argument of callback */ 2N/A** Possible values for the sqlite.magic field. 2N/A** The numbers are obtained at random and have no special meaning, other 2N/A** than being distinct from one another. 2N/A** Each SQL function is defined by an instance of the following 2N/A** structure. A pointer to this structure is stored in the sqlite.aFunc 2N/A** hash table. When multiple functions have the same name, the hash table 2N/A** points to a linked list of these structures. 2N/A signed char nArg;
/* Number of arguments. -1 means unlimited */ 2N/A signed char dataType;
/* Arg that determines datatype. -1=NUMERIC, */ 2N/A /* -2=TEXT. -3=SQLITE_ARGS */ 2N/A** information about each column of an SQL table is held in an instance 2N/A** of this structure. 2N/A char *
zDflt;
/* Default value of this column */ 2N/A char *
zType;
/* Data type for this column */ 2N/A** The allowed sort orders. 2N/A** The TEXT and NUM values use bits that do not overlap with DESC and ASC. 2N/A** That way the two can be combined into a single number. 2N/A** Each SQL table is represented in memory by an instance of the 2N/A** following structure. 2N/A** Table.zName is the name of the table. The case of the original 2N/A** CREATE TABLE statement is stored, but case is not significant for 2N/A** Table.nCol is the number of columns in this table. Table.aCol is a 2N/A** pointer to an array of Column structures, one for each column. 2N/A** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of 2N/A** the column that is that key. Otherwise Table.iPKey is negative. Note 2N/A** that the datatype of the PRIMARY KEY must be INTEGER for this field to 2N/A** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of 2N/A** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid 2N/A** is generated for each row of the table. Table.hasPrimKey is true if 2N/A** the table has any PRIMARY KEY, INTEGER or otherwise. 2N/A** Table.tnum is the page number for the root BTree page of the table in the 2N/A** database file. If Table.iDb is the index of the database table backend 2N/A** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that 2N/A** holds temporary tables and indices. If Table.isTransient 2N/A** is true, then the table is stored in a file that is automatically deleted 2N/A** when the VDBE cursor to the table is closed. In this case Table.tnum 2N/A** refers VDBE cursor number that holds the table open, not to the root 2N/A** page number. Transient tables are used to hold the results of a 2N/A** sub-query that appears instead of a real table name in the FROM clause 2N/A** of a SELECT statement. 2N/A int nCol;
/* Number of columns in this table */ 2N/A int iPKey;
/* If not less then 0, use aCol[iPKey] as the primary key */ 2N/A int tnum;
/* Root BTree node for this table (see note above) */ 2N/A u8 readOnly;
/* True if this table should not be written by the user */ 2N/A u8 iDb;
/* Index into sqlite.aDb[] of the backend for this table */ 2N/A u8 keyConf;
/* What to do in case of uniqueness conflict on iPKey */ 2N/A FKey *
pFKey;
/* Linked list of all foreign keys in this table */ 2N/A** Each foreign key constraint is an instance of the following structure. 2N/A** A foreign key is associated with two tables. The "from" table is 2N/A** the table that contains the REFERENCES clause that creates the foreign 2N/A** key. The "to" table is the table that is named in the REFERENCES clause. 2N/A** Consider this example: 2N/A** a INTEGER PRIMARY KEY, 2N/A** b INTEGER CONSTRAINT fk1 REFERENCES ex2(x) 2N/A** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2". 2N/A** Each REFERENCES clause generates an instance of the following structure 2N/A** which is attached to the from-table. The to-table need not exist when 2N/A** the from-table is created. The existance of the to-table is not checked 2N/A** until an attempt is made to insert data into the from-table. 2N/A** The sqlite.aFKey hash table stores pointers to this structure 2N/A** given the name of a to-table. For each to-table, all foreign keys 2N/A** associated with that table are on a linked list using the FKey.pNextTo 2N/A Table *
pFrom;
/* The table that constains the REFERENCES clause */ 2N/A char *
zTo;
/* Name of table that the key points to */ 2N/A int nCol;
/* Number of columns in this key */ 2N/A struct sColMap {
/* Mapping of columns in pFrom to columns in zTo */ 2N/A int iFrom;
/* Index of column in pFrom */ 2N/A char *
zCol;
/* Name of column in zTo. If 0 use PRIMARY KEY */ 2N/A } *
aCol;
/* One entry for each of nCol column s */ 2N/A** SQLite supports many different ways to resolve a contraint 2N/A** error. ROLLBACK processing means that a constraint violation 2N/A** causes the operation in process to fail and for the current transaction 2N/A** to be rolled back. ABORT processing means the operation in process 2N/A** fails and any prior changes from that one operation are backed out, 2N/A** but the transaction is not rolled back. FAIL processing means that 2N/A** the operation in progress stops and returns an error code. But prior 2N/A** changes due to the same operation are not backed out and no rollback 2N/A** occurs. IGNORE means that the particular row that caused the constraint 2N/A** error is not inserted or updated. Processing continues and no error 2N/A** is returned. REPLACE means that preexisting database rows that caused 2N/A** a UNIQUE constraint violation are removed so that the new insert or 2N/A** update can proceed. Processing continues and no error is reported. 2N/A** RESTRICT, SETNULL, and CASCADE actions apply only to foreign keys. 2N/A** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the 2N/A** same as ROLLBACK for DEFERRED keys. SETNULL means that the foreign 2N/A** key is set to NULL. CASCADE means that a DELETE or UPDATE of the 2N/A** referenced table row is propagated into the row that holds the 2N/A** The following symbolic values are used to record which type 2N/A** of action to take. 2N/A#
define OE_None 0
/* There is no constraint to check */ 2N/A#
define OE_Rollback 1 /* Fail the operation and rollback the transaction */ 2N/A#
define OE_Abort 2 /* Back out changes but do no rollback transaction */ 2N/A#
define OE_Fail 3 /* Stop the operation but leave all prior changes */ 2N/A#
define OE_Ignore 4 /* Ignore the error. Do not do the INSERT or UPDATE */ 2N/A#
define OE_Replace 5 /* Delete existing record, then do INSERT or UPDATE */ 2N/A#
define OE_Restrict 6 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */ 2N/A#
define OE_SetDflt 8 /* Set the foreign key value to its default */ 2N/A** Each SQL index is represented in memory by an 2N/A** instance of the following structure. 2N/A** The columns of the table that are to be indexed are described 2N/A** by the aiColumn[] field of this structure. For example, suppose 2N/A** we have the following table and index: 2N/A** CREATE TABLE Ex1(c1 int, c2 int, c3 text); 2N/A** CREATE INDEX Ex2 ON Ex1(c3,c1); 2N/A** In the Table structure describing Ex1, nCol==3 because there are 2N/A** three columns in the table. In the Index structure describing 2N/A** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed. 2N/A** The value of aiColumn is {2, 0}. aiColumn[0]==2 because the 2N/A** first column to be indexed (c3) has an index of 2 in Ex1.aCol[]. 2N/A** The second column to be indexed (c1) has an index of 0 in 2N/A** Ex1.aCol[], hence Ex2.aiColumn[1]==0. 2N/A** The Index.onError field determines whether or not the indexed columns 2N/A** must be unique and what to do if they are not. When Index.onError=OE_None, 2N/A** it means this is not a unique index. Otherwise it is a unique index 2N/A** and the value of Index.onError indicate the which conflict resolution 2N/A** algorithm to employ whenever an attempt is made to insert a non-unique 2N/A int nColumn;
/* Number of columns in the table used by this index */ 2N/A int *
aiColumn;
/* Which columns are used by this index. 1st is 0 */ 2N/A int tnum;
/* Page containing root of this index in database file */ 2N/A u8 onError;
/* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ 2N/A u8 iDb;
/* Index in sqlite.aDb[] of where this index is stored */ 2N/A Index *
pNext;
/* The next index associated with the same table */ 2N/A** Each token coming out of the lexer is an instance of 2N/A** this structure. Tokens are also used as part of an expression. 2N/A** Note if Token.z==0 then Token.dyn and Token.n are undefined and 2N/A** may contain random values. Do not make any assuptions about Token.dyn 2N/A** and Token.n when Token.z==0. 2N/A const char *z;
/* Text of the token. Not NULL-terminated! */ 2N/A unsigned dyn :
1;
/* True for malloced memory, false for static */ 2N/A unsigned n :
31;
/* Number of characters in this token */ 2N/A** Each node of an expression in the parse tree is an instance 2N/A** of this structure. 2N/A** Expr.op is the opcode. The integer parser token codes are reused 2N/A** as opcodes here. For example, the parser defines TK_GE to be an integer 2N/A** code representing the ">=" operator. This same integer code is reused 2N/A** to represent the greater-than-or-equal-to operator in the expression 2N/A** of argument if the expression is a function. 2N/A** Expr.token is the operator token for this node. For some expressions 2N/A** that have subexpressions, Expr.token can be the complete text that gave 2N/A** rise to the Expr. In the latter case, the token is marked as being 2N/A** An expression of the form ID or ID.ID refers to a column in a table. 2N/A** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is 2N/A** the integer cursor number of a VDBE cursor pointing to that table and 2N/A** Expr.iColumn is the column number for the specific column. If the 2N/A** expression is used as a result in an aggregate SELECT, then the 2N/A** value is also stored in the Expr.iAgg column in the aggregate so that 2N/A** it can be accessed after all aggregates are computed. 2N/A** If the expression is a function, the Expr.iTable is an integer code 2N/A** representing which function. If the expression is an unbound variable 2N/A** marker (a question mark character '?' in the original SQL) then the 2N/A** Expr.iTable holds the index number for that variable. 2N/A** The Expr.pSelect field points to a SELECT statement. The SELECT might 2N/A** be the right operand of an IN operator. Or, if a scalar SELECT appears 2N/A** in an expression the opcode is TK_SELECT and Expr.pSelect is the only 2N/A u8 op;
/* Operation performed by this node */ 2N/A u8 iDb;
/* Database referenced by this expression */ 2N/A ** or in "<expr> IN (<expr-list)" */ 2N/A ** iColumn-th field of the iTable-th table. */ 2N/A int iAgg;
/* When op==TK_COLUMN and pParse->useAgg==TRUE, pull 2N/A ** result from the iAgg-th element of the aggregator */ 2N/A ** right side of "<expr> IN (<select>)" */ 2N/A** The following are the meanings of bits in the Expr.flags field. 2N/A#
define EP_FromJoin 0x0001 /* Originated in ON or USING clause of a join */ 2N/A** These macros can be used to test, set, or clear bits in the 2N/A** A list of expressions. Each expression may optionally have a 2N/A** name. An expr/name combination can be used in several ways, such 2N/A** as the list of "expr AS ID" fields following a "SELECT" or in the 2N/A** list of "ID = expr" items in an UPDATE. A list of expressions can 2N/A** also be used as the argument to a function, in which case the a.zName 2N/A** field is not used. 2N/A int nExpr;
/* Number of expressions on the list */ 2N/A int nAlloc;
/* Number of entries allocated below */ 2N/A char *
zName;
/* Token associated with this expression */ 2N/A u8 isAgg;
/* True if this is an aggregate like count(*) */ 2N/A u8 done;
/* A flag to indicate when processing is finished */ 2N/A } *a;
/* One entry for each expression */ 2N/A** An instance of this structure can hold a simple list of identifiers, 2N/A** such as the list "a,b,c" in the following statements: 2N/A** INSERT INTO t(a,b,c) VALUES ...; 2N/A** CREATE INDEX idx ON t(a,b,c); 2N/A** CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...; 2N/A** The IdList.a.idx field is used when the IdList represents the list of 2N/A** column names after a table name in an INSERT statement. In the statement 2N/A** INSERT INTO t(a,b,c) ... 2N/A** If "a" is the k-th column of table "t", then IdList.a[0].idx==k. 2N/A int nId;
/* Number of identifiers on the list */ 2N/A int nAlloc;
/* Number of entries allocated for a[] below */ 2N/A char *
zName;
/* Name of the identifier */ 2N/A int idx;
/* Index in some Table.aCol[] of a column named zName */ 2N/A** The following structure describes the FROM clause of a SELECT statement. 2N/A** Each table or subquery in the FROM clause is a separate element of 2N/A** the SrcList.a[] array. 2N/A** With the addition of multiple database support, the following structure 2N/A** can also be used to describe a particular table such as the table that 2N/A** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL, 2N/A** such a table must be a simple name: ID. But in SQLite, the table can 2N/A** now be identified by a database name, a dot, then the table name: ID.ID. 2N/A i16 nSrc;
/* Number of tables or subqueries in the FROM clause */ 2N/A char *
zAlias;
/* The "B" part of a "A AS B" phrase. zName is the "A" */ 2N/A int jointype;
/* Type of join between this table and the next */ 2N/A int iCursor;
/* The VDBE cursor number used to access this table */ 2N/A } a[
1];
/* One entry for each identifier on the list */ 2N/A** Permitted values of the SrcList.a.jointype field 2N/A#
define JT_INNER 0x0001 /* Any kind of inner or cross join */ 2N/A#
define JT_OUTER 0x0010 /* The "OUTER" keyword is present */ 2N/A#
define JT_ERROR 0x0020 /* unknown or unsupported join type */ 2N/A** For each nested loop in a WHERE clause implementation, the WhereInfo 2N/A** structure contains a single instance of this structure. This structure 2N/A** is intended to be private the the where.c module and should not be 2N/A** access or modified by other modules. 2N/A int iMem;
/* Memory cell used by this level */ 2N/A int iCur;
/* Cursor number used for this index */ 2N/A int score;
/* How well this indexed scored */ 2N/A int brk;
/* Jump here to break out of the loop */ 2N/A int cont;
/* Jump here to continue with the next loop cycle */ 2N/A int op,
p1,
p2;
/* Opcode used to terminate the loop */ 2N/A int iLeftJoin;
/* Memory cell used to implement LEFT OUTER JOIN */ 2N/A int top;
/* First instruction of interior of the loop */ 2N/A int bRev;
/* Do the scan in the reverse direction */ 2N/A** The WHERE clause processing routine has two halves. The 2N/A** first part does the start of the WHERE loop and the second 2N/A** half does the tail of the WHERE loop. An instance of 2N/A** this structure is returned by the first half and passed 2N/A** into the second half to give some continuity. 2N/A int iBreak;
/* Jump here to break out of the loop */ 2N/A int savedNTab;
/* Value of pParse->nTab before WhereBegin() */ 2N/A int peakNTab;
/* Value of pParse->nTab after WhereBegin() */ 2N/A WhereLevel a[
1];
/* Information about each nest loop in the WHERE */ 2N/A** An instance of the following structure contains all information 2N/A** needed to generate code for a single SELECT statement. 2N/A** The zSelect field is used when the Select structure must be persistent. 2N/A** Normally, the expression tree points to tokens in the original input 2N/A** string that encodes the select. But if the Select structure must live 2N/A** longer than its input string (for example when it is used to describe 2N/A** a VIEW) we have to make a copy of the input string so that the nodes 2N/A** of the expression tree will have something to point to. zSelect is used 2N/A** to hold that copy. 2N/A** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0. 2N/A** If there is a LIMIT clause, the parser sets nLimit to the value of the 2N/A** limit and nOffset to the value of the offset (or 0 if there is not 2N/A** offset). But later on, nLimit and nOffset become the memory locations 2N/A** in the VDBE that record the limit and offset counters. 2N/A u8 op;
/* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */ 2N/A char *
zSelect;
/* Complete text of the SELECT command */ 2N/A** The results of a select can be distributed in several ways. 2N/A#
define SRT_Mem 2 /* Store result in a memory cell */ 2N/A#
define SRT_Set 3 /* Store result as unique keys in a table */ 2N/A#
define SRT_Table 7 /* Store result as data with a unique key */ 2N/A** When a SELECT uses aggregate functions (like "count(*)" or "avg(f1)") 2N/A** we have to do some additional analysis of expressions. An instance 2N/A** of the following structure holds information about a single subexpression 2N/A** somewhere in the SELECT statement. An array of these structures holds 2N/A** all the information we need to generate code for aggregate 2N/A** Note that when analyzing a SELECT containing aggregates, both 2N/A** non-aggregate field variables and aggregate functions are stored 2N/A** in the AggExpr array of the Parser structure. 2N/A** The pExpr field points to an expression that is part of either the 2N/A** field list, the GROUP BY clause, the HAVING clause or the ORDER BY 2N/A** clause. The expression will be freed when those clauses are cleaned 2N/A** up. Do not try to delete the expression attached to AggExpr.pExpr. 2N/A** If AggExpr.pExpr==0, that means the expression is "count(*)". 2N/A int isAgg;
/* if TRUE contains an aggregate function */ 2N/A** An SQL parser context. A copy of this structure is passed through 2N/A** the parser and down into all the parser action routine in order to 2N/A** carry around information that is global to the entire parse. 2N/A int rc;
/* Return code from execution */ 2N/A const char *
zTail;
/* All SQL text past the last semicolon parsed */ 2N/A Vdbe *
pVdbe;
/* An engine for executing database bytecode */ 2N/A u8 explain;
/* True if the EXPLAIN flag is found on the query */ 2N/A u8 nameClash;
/* A permanent table name clashes with temp table name */ 2N/A u8 useAgg;
/* If true, extract field values from the aggregator 2N/A ** while generating expressions. Normally false */ 2N/A int nErr;
/* Number of errors seen */ 2N/A int nTab;
/* Number of previously allocated VDBE cursors */ 2N/A int nMem;
/* Number of memory cells used so far */ 2N/A int nSet;
/* Number of sets used so far */ 2N/A int nAgg;
/* Number of aggregate expressions */ 2N/A int nVar;
/* Number of '?' variables seen in the SQL so far */ 2N/A** An instance of the following structure can be declared on a stack and used 2N/A** to save the Parse.zAuthContext value so that it can be restored later. 2N/A** Bitfield flags for P2 value in OP_PutIntKey and OP_Delete 2N/A * Each trigger present in the database schema is stored as an instance of 2N/A * Pointers to instances of struct Trigger are stored in two ways. 2N/A * 1. In the "trigHash" hash table (part of the sqlite* that represents the 2N/A * database). This allows Trigger structures to be retrieved by name. 2N/A * 2. All triggers associated with a single table form a linked list, using the 2N/A * pNext member of struct Trigger. A pointer to the first element of the 2N/A * linked list is stored as the "pTrigger" member of the associated 2N/A * The "step_list" member points to the first element of a linked list 2N/A * containing the SQL statements specified as the trigger program. 2N/A char *
name;
/* The name of the trigger */ 2N/A char *
table;
/* The table or view to which the trigger applies */ 2N/A u8 iDb;
/* Database containing this trigger */ 2N/A u8 op;
/* One of TK_DELETE, TK_UPDATE, TK_INSERT */ 2N/A Expr *
pWhen;
/* The WHEN clause of the expresion (may be NULL) */ 2N/A the <column-list> is stored here */ 2N/A * An instance of struct TriggerStep is used to store a single SQL statement 2N/A * that is a part of a trigger-program. 2N/A * Instances of struct TriggerStep are stored in a singly linked list (linked 2N/A * using the "pNext" member) referenced by the "step_list" member of the 2N/A * associated struct Trigger instance. The first element of the linked list is 2N/A * the first step of the trigger-program. 2N/A * The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or 2N/A * "SELECT" statement. The meanings of the other members is determined by the 2N/A * value of "op" as follows: 2N/A * orconf -> stores the ON CONFLICT algorithm 2N/A * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then 2N/A * this stores a pointer to the SELECT statement. Otherwise NULL. 2N/A * target -> A token holding the name of the table to insert into. 2N/A * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then 2N/A * this stores values to be inserted. Otherwise NULL. 2N/A * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ... 2N/A * statement, then this stores the column-names to be 2N/A * target -> A token holding the name of the table to delete from. 2N/A * pWhere -> The WHERE clause of the DELETE statement if one is specified. 2N/A * target -> A token holding the name of the table to update rows of. 2N/A * pWhere -> The WHERE clause of the UPDATE statement if one is specified. 2N/A * pExprList -> A list of the columns to update and the expressions to update 2N/A * them to. See sqliteUpdate() documentation of "pChanges" 2N/A int op;
/* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */ 2N/A INSERT steps (when pExprList == 0) */ 2N/A INSERT steps (when pSelect == 0) */ 2N/A * An instance of struct TriggerStack stores information required during code 2N/A * generation of a single trigger program. While the trigger program is being 2N/A * coded, its associated TriggerStack instance is pointed to by the 2N/A * "pTriggerStack" member of the Parse structure. 2N/A * The pTab member points to the table that triggers are being coded on. The 2N/A * newIdx member contains the index of the vdbe cursor that points at the temp 2N/A * table that stores the new.* references. If new.* references are not valid 2N/A * for the trigger being coded (for example an ON DELETE trigger), then newIdx 2N/A * is set to -1. The oldIdx member is analogous to newIdx, for old.* references. 2N/A * The ON CONFLICT policy to be used for the trigger program steps is stored 2N/A * as the orconf member. If this is OE_Default, then the ON CONFLICT clause 2N/A * specified for individual triggers steps is used. 2N/A * struct TriggerStack has a "pNext" member, to allow linked lists to be 2N/A * constructed. When coding nested triggers (triggers fired by other triggers) 2N/A * each nested trigger stores its parent trigger's TriggerStack as the "pNext" 2N/A * pointer. Once the nested trigger has been coded, the pNext value is restored 2N/A * to the pTriggerStack member of the Parse stucture and coding of the parent 2N/A * trigger continues. 2N/A * Before a nested trigger is coded, the linked list pointed to by the 2N/A * pTriggerStack is scanned to ensure that the trigger is not about to be coded 2N/A * recursively. If this condition is detected, the nested trigger is not coded. 2N/A Table *
pTab;
/* Table that triggers are currently being coded on */ 2N/A int newIdx;
/* Index of vdbe cursor to "new" temp table */ 2N/A int oldIdx;
/* Index of vdbe cursor to "old" temp table */ 2N/A** The following structure contains information used by the sqliteFix... 2N/A** routines as they walk the parse tree to make database references 2N/A const char *
zDb;
/* Make sure all objects are contained in this database */ 2N/A const char *
zType;
/* Type of the container - used for error messages */ 2N/A const Token *
pName;
/* Name of the container - used for error messages */ 2N/A * This global flag is set for performance testing of triggers. When it is set 2N/A * SQLite will perform the overhead of building new and old trigger references 2N/A * even when no triggers exist 2N/A** Internal function prototypes