2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A** 2001 September 15
2N/A**
2N/A** The author disclaims copyright to this source code. In place of
2N/A** a legal notice, here is a blessing:
2N/A**
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*************************************************************************
2N/A** Internal interface definitions for SQLite.
2N/A**
2N/A** @(#) $Id: sqliteInt.h,v 1.220.2.1 2004/07/15 13:37:05 drh Exp $
2N/A*/
2N/A#include "config.h"
2N/A#include "sqlite.h"
2N/A#include "hash.h"
2N/A#include "parse.h"
2N/A#include "btree.h"
2N/A#include <stdio.h>
2N/A#include <stdlib.h>
2N/A#include <string.h>
2N/A#include <assert.h>
2N/A
2N/A/*
2N/A** The maximum number of in-memory pages to use for the main database
2N/A** table and for temporary tables.
2N/A*/
2N/A#define MAX_PAGES 2000
2N/A#define TEMP_PAGES 500
2N/A
2N/A/*
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**
2N/A** If the following macro is set to 0, then NULLs are indistinct for
2N/A** SELECT DISTINCT and for UNION.
2N/A*/
2N/A#define NULL_ALWAYS_DISTINCT 0
2N/A
2N/A/*
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**
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** work.
2N/A*/
2N/A#define NULL_DISTINCT_FOR_UNIQUE 1
2N/A
2N/A/*
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*/
2N/A#define MAX_ATTACHED 10
2N/A
2N/A/*
2N/A** The next macro is used to determine where TEMP tables and indices
2N/A** are stored. Possible values:
2N/A**
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*/
2N/A#ifndef TEMP_STORE
2N/A# define TEMP_STORE 1
2N/A#endif
2N/A
2N/A/*
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** a minimum.
2N/A*/
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
2N/A/*
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**
2N/A** cc '-DUINTPTR_TYPE=long long int' ...
2N/A*/
2N/A#ifndef UINT32_TYPE
2N/A# define UINT32_TYPE unsigned int
2N/A#endif
2N/A#ifndef UINT16_TYPE
2N/A# define UINT16_TYPE unsigned short int
2N/A#endif
2N/A#ifndef INT16_TYPE
2N/A# define INT16_TYPE short int
2N/A#endif
2N/A#ifndef UINT8_TYPE
2N/A# define UINT8_TYPE unsigned char
2N/A#endif
2N/A#ifndef INT8_TYPE
2N/A# define INT8_TYPE signed char
2N/A#endif
2N/A#ifndef INTPTR_TYPE
2N/A# if SQLITE_PTR_SZ==4
2N/A# define INTPTR_TYPE int
2N/A# else
2N/A# define INTPTR_TYPE long long
2N/A# endif
2N/A#endif
2N/Atypedef UINT32_TYPE u32; /* 4-byte unsigned integer */
2N/Atypedef UINT16_TYPE u16; /* 2-byte unsigned integer */
2N/Atypedef INT16_TYPE i16; /* 2-byte signed integer */
2N/Atypedef UINT8_TYPE u8; /* 1-byte unsigned integer */
2N/Atypedef UINT8_TYPE i8; /* 1-byte signed integer */
2N/Atypedef INTPTR_TYPE ptr; /* Big enough to hold a pointer */
2N/Atypedef unsigned INTPTR_TYPE uptr; /* Big enough to hold a pointer */
2N/A
2N/A/*
2N/A** Defer sourcing vdbe.h until after the "u8" typedef is defined.
2N/A*/
2N/A#include "vdbe.h"
2N/A
2N/A/*
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*/
2N/A#ifndef LONGDOUBLE_TYPE
2N/A# define LONGDOUBLE_TYPE long double
2N/A#endif
2N/A
2N/A/*
2N/A** This macro casts a pointer to an integer. Useful for doing
2N/A** pointer arithmetic.
2N/A*/
2N/A#define Addr(X) ((uptr)X)
2N/A
2N/A/*
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** size.
2N/A**
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** data.
2N/A*/
2N/A#define MAX_BYTES_PER_ROW 1048576
2N/A/* #define MAX_BYTES_PER_ROW 16777198 */
2N/A
2N/A/*
2N/A** If memory allocation problems are found, recompile with
2N/A**
2N/A** -DMEMORY_DEBUG=1
2N/A**
2N/A** to enable some sanity checking on malloc() and free(). To
2N/A** check for memory leaks, recompile with
2N/A**
2N/A** -DMEMORY_DEBUG=2
2N/A**
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*/
2N/A#ifdef MEMORY_DEBUG
2N/A# define sqliteMalloc(X) sqliteMalloc_(X,1,__FILE__,__LINE__)
2N/A# define sqliteMallocRaw(X) sqliteMalloc_(X,0,__FILE__,__LINE__)
2N/A# define sqliteFree(X) sqliteFree_(X,__FILE__,__LINE__)
2N/A# define sqliteRealloc(X,Y) sqliteRealloc_(X,Y,__FILE__,__LINE__)
2N/A# define sqliteStrDup(X) sqliteStrDup_(X,__FILE__,__LINE__)
2N/A# define sqliteStrNDup(X,Y) sqliteStrNDup_(X,Y,__FILE__,__LINE__)
2N/A void sqliteStrRealloc(char**);
2N/A#else
2N/A# define sqliteRealloc_(X,Y) sqliteRealloc(X,Y)
2N/A# define sqliteStrRealloc(X)
2N/A#endif
2N/A
2N/A/*
2N/A** This variable gets set if malloc() ever fails. After it gets set,
2N/A** the SQLite library shuts down permanently.
2N/A*/
2N/Aextern int sqlite_malloc_failed;
2N/A
2N/A/*
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*/
2N/A#ifdef MEMORY_DEBUG
2N/Aextern int sqlite_nMalloc; /* Number of sqliteMalloc() calls */
2N/Aextern int sqlite_nFree; /* Number of sqliteFree() calls */
2N/Aextern int sqlite_iMallocFail; /* Fail sqliteMalloc() after this many calls */
2N/A#endif
2N/A
2N/A/*
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*/
2N/A#define MASTER_NAME "sqlite_master"
2N/A#define TEMP_MASTER_NAME "sqlite_temp_master"
2N/A
2N/A/*
2N/A** The name of the schema table.
2N/A*/
2N/A#define SCHEMA_TABLE(x) (x?TEMP_MASTER_NAME:MASTER_NAME)
2N/A
2N/A/*
2N/A** A convenience macro that returns the number of elements in
2N/A** an array.
2N/A*/
2N/A#define ArraySize(X) (sizeof(X)/sizeof(X[0]))
2N/A
2N/A/*
2N/A** Forward references to structures
2N/A*/
2N/Atypedef struct Column Column;
2N/Atypedef struct Table Table;
2N/Atypedef struct Index Index;
2N/Atypedef struct Instruction Instruction;
2N/Atypedef struct Expr Expr;
2N/Atypedef struct ExprList ExprList;
2N/Atypedef struct Parse Parse;
2N/Atypedef struct Token Token;
2N/Atypedef struct IdList IdList;
2N/Atypedef struct SrcList SrcList;
2N/Atypedef struct WhereInfo WhereInfo;
2N/Atypedef struct WhereLevel WhereLevel;
2N/Atypedef struct Select Select;
2N/Atypedef struct AggExpr AggExpr;
2N/Atypedef struct FuncDef FuncDef;
2N/Atypedef struct Trigger Trigger;
2N/Atypedef struct TriggerStep TriggerStep;
2N/Atypedef struct TriggerStack TriggerStack;
2N/Atypedef struct FKey FKey;
2N/Atypedef struct Db Db;
2N/Atypedef struct AuthContext AuthContext;
2N/A
2N/A/*
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*/
2N/Astruct Db {
2N/A char *zName; /* Name of this database */
2N/A Btree *pBt; /* The B*Tree structure for this database file */
2N/A int schema_cookie; /* Database schema version number for this file */
2N/A Hash tblHash; /* All tables indexed by name */
2N/A Hash idxHash; /* All (named) indices indexed by name */
2N/A Hash trigHash; /* All triggers indexed by name */
2N/A Hash aFKey; /* Foreign keys indexed by to-table */
2N/A u8 inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */
2N/A u16 flags; /* Flags associated with this database */
2N/A void *pAux; /* Auxiliary data. Usually NULL */
2N/A void (*xFreeAux)(void*); /* Routine to free pAux */
2N/A};
2N/A
2N/A/*
2N/A** These macros can be used to test, set, or clear bits in the
2N/A** Db.flags field.
2N/A*/
2N/A#define DbHasProperty(D,I,P) (((D)->aDb[I].flags&(P))==(P))
2N/A#define DbHasAnyProperty(D,I,P) (((D)->aDb[I].flags&(P))!=0)
2N/A#define DbSetProperty(D,I,P) (D)->aDb[I].flags|=(P)
2N/A#define DbClearProperty(D,I,P) (D)->aDb[I].flags&=~(P)
2N/A
2N/A/*
2N/A** Allowed values for the DB.flags field.
2N/A**
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** down execution.
2N/A**
2N/A** The DB_SchemaLoaded flag is set after the database schema has been
2N/A** read into internal hash tables.
2N/A**
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*/
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#define DB_SchemaLoaded 0x0004 /* The schema has been loaded */
2N/A#define DB_UnresetViews 0x0008 /* Some views have defined column names */
2N/A
2N/A
2N/A/*
2N/A** Each database is an instance of the following structure.
2N/A**
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** are as follows:
2N/A**
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** text datatypes.
2N/A**
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**
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**
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*/
2N/Astruct sqlite {
2N/A int nDb; /* Number of backends currently in use */
2N/A Db *aDb; /* All backends */
2N/A Db aDbStatic[2]; /* Static space for the 2 default backends */
2N/A int flags; /* Miscellanous flags. See below */
2N/A u8 file_format; /* What file format version is this database? */
2N/A u8 safety_level; /* How aggressive at synching data to disk */
2N/A u8 want_to_close; /* Close after all VDBEs are deallocated */
2N/A u8 temp_store; /* 1=file, 2=memory, 0=compile-time default */
2N/A u8 onError; /* Default conflict algorithm */
2N/A int next_cookie; /* Next value of aDb[0].schema_cookie */
2N/A int cache_size; /* Number of pages to use in the cache */
2N/A int nTable; /* Number of tables in the database */
2N/A void *pBusyArg; /* 1st Argument to the busy callback */
2N/A int (*xBusyCallback)(void *,const char*,int); /* The busy callback */
2N/A void *pCommitArg; /* Argument to xCommitCallback() */
2N/A int (*xCommitCallback)(void*);/* Invoked at every commit. */
2N/A Hash aFunc; /* All functions that can be in SQL exprs */
2N/A int lastRowid; /* ROWID of most recent insert (see above) */
2N/A int priorNewRowid; /* Last randomly generated ROWID */
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 struct sqliteInitInfo { /* Information used during initialization */
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 } init;
2N/A struct Vdbe *pVdbe; /* List of active virtual machines */
2N/A void (*xTrace)(void*,const char*); /* Trace function */
2N/A void *pTraceArg; /* Argument to the trace function */
2N/A#ifndef SQLITE_OMIT_AUTHORIZATION
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#endif
2N/A#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
2N/A int (*xProgress)(void *); /* The progress callback */
2N/A void *pProgressArg; /* Argument to the progress callback */
2N/A int nProgressOps; /* Number of opcodes for progress callback */
2N/A#endif
2N/A};
2N/A
2N/A/*
2N/A** Possible values for the sqlite.flags and or Db.flags fields.
2N/A**
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*/
2N/A#define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
2N/A#define SQLITE_Initialized 0x00000002 /* True after initialization */
2N/A#define SQLITE_Interrupt 0x00000004 /* Cancel current operation */
2N/A#define SQLITE_InTrans 0x00000008 /* True if in a transaction */
2N/A#define SQLITE_InternChanges 0x00000010 /* Uncommitted Hash table changes */
2N/A#define SQLITE_FullColNames 0x00000020 /* Show full column names on SELECT */
2N/A#define SQLITE_ShortColNames 0x00000040 /* Show short columns names */
2N/A#define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */
2N/A /* DELETE, or UPDATE and return */
2N/A /* the count using a callback. */
2N/A#define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */
2N/A /* result set is empty */
2N/A#define SQLITE_ReportTypes 0x00000200 /* Include information on datatypes */
2N/A /* in 4th argument of callback */
2N/A
2N/A/*
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*/
2N/A#define SQLITE_MAGIC_OPEN 0xa029a697 /* Database is open */
2N/A#define SQLITE_MAGIC_CLOSED 0x9f3c2d33 /* Database is closed */
2N/A#define SQLITE_MAGIC_BUSY 0xf03b7906 /* Database currently in use */
2N/A#define SQLITE_MAGIC_ERROR 0xb5357930 /* An SQLITE_MISUSE error occurred */
2N/A
2N/A/*
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*/
2N/Astruct FuncDef {
2N/A void (*xFunc)(sqlite_func*,int,const char**); /* Regular function */
2N/A void (*xStep)(sqlite_func*,int,const char**); /* Aggregate function step */
2N/A void (*xFinalize)(sqlite_func*); /* Aggregate function finializer */
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 u8 includeTypes; /* Add datatypes to args of xFunc and xStep */
2N/A void *pUserData; /* User data parameter */
2N/A FuncDef *pNext; /* Next function with same name */
2N/A};
2N/A
2N/A/*
2N/A** information about each column of an SQL table is held in an instance
2N/A** of this structure.
2N/A*/
2N/Astruct Column {
2N/A char *zName; /* Name of this column */
2N/A char *zDflt; /* Default value of this column */
2N/A char *zType; /* Data type for this column */
2N/A u8 notNull; /* True if there is a NOT NULL constraint */
2N/A u8 isPrimKey; /* True if this column is part of the PRIMARY KEY */
2N/A u8 sortOrder; /* Some combination of SQLITE_SO_... values */
2N/A u8 dottedName; /* True if zName contains a "." character */
2N/A};
2N/A
2N/A/*
2N/A** The allowed sort orders.
2N/A**
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*/
2N/A#define SQLITE_SO_UNK 0 /* Use the default collating type. (SCT_NUM) */
2N/A#define SQLITE_SO_TEXT 2 /* Sort using memcmp() */
2N/A#define SQLITE_SO_NUM 4 /* Sort using sqliteCompare() */
2N/A#define SQLITE_SO_TYPEMASK 6 /* Mask to extract the collating sequence */
2N/A#define SQLITE_SO_ASC 0 /* Sort in ascending order */
2N/A#define SQLITE_SO_DESC 1 /* Sort in descending order */
2N/A#define SQLITE_SO_DIRMASK 1 /* Mask to extract the sort direction */
2N/A
2N/A/*
2N/A** Each SQL table is represented in memory by an instance of the
2N/A** following structure.
2N/A**
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** comparisons.
2N/A**
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**
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**
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*/
2N/Astruct Table {
2N/A char *zName; /* Name of the table */
2N/A int nCol; /* Number of columns in this table */
2N/A Column *aCol; /* Information about each column */
2N/A int iPKey; /* If not less then 0, use aCol[iPKey] as the primary key */
2N/A Index *pIndex; /* List of SQL indexes on this table. */
2N/A int tnum; /* Root BTree node for this table (see note above) */
2N/A Select *pSelect; /* NULL for tables. Points to definition if a view. */
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 isTransient; /* True if automatically deleted when VDBE finishes */
2N/A u8 hasPrimKey; /* True if there exists a primary key */
2N/A u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
2N/A Trigger *pTrigger; /* List of SQL triggers on this table */
2N/A FKey *pFKey; /* Linked list of all foreign keys in this table */
2N/A};
2N/A
2N/A/*
2N/A** Each foreign key constraint is an instance of the following structure.
2N/A**
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**
2N/A** CREATE TABLE ex1(
2N/A** a INTEGER PRIMARY KEY,
2N/A** b INTEGER CONSTRAINT fk1 REFERENCES ex2(x)
2N/A** );
2N/A**
2N/A** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2".
2N/A**
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**
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** field.
2N/A*/
2N/Astruct FKey {
2N/A Table *pFrom; /* The table that constains the REFERENCES clause */
2N/A FKey *pNextFrom; /* Next foreign key in pFrom */
2N/A char *zTo; /* Name of table that the key points to */
2N/A FKey *pNextTo; /* Next foreign key that points to zTo */
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 u8 isDeferred; /* True if constraint checking is deferred till COMMIT */
2N/A u8 updateConf; /* How to resolve conflicts that occur on UPDATE */
2N/A u8 deleteConf; /* How to resolve conflicts that occur on DELETE */
2N/A u8 insertConf; /* How to resolve conflicts that occur on INSERT */
2N/A};
2N/A
2N/A/*
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**
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** foreign key.
2N/A**
2N/A** The following symbolic values are used to record which type
2N/A** of action to take.
2N/A*/
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
2N/A#define OE_Restrict 6 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */
2N/A#define OE_SetNull 7 /* Set the foreign key value to NULL */
2N/A#define OE_SetDflt 8 /* Set the foreign key value to its default */
2N/A#define OE_Cascade 9 /* Cascade the changes */
2N/A
2N/A#define OE_Default 99 /* Do whatever the default action is */
2N/A
2N/A/*
2N/A** Each SQL index is represented in memory by an
2N/A** instance of the following structure.
2N/A**
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**
2N/A** CREATE TABLE Ex1(c1 int, c2 int, c3 text);
2N/A** CREATE INDEX Ex2 ON Ex1(c3,c1);
2N/A**
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**
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** element.
2N/A*/
2N/Astruct Index {
2N/A char *zName; /* Name of this index */
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 Table *pTable; /* The SQL table being indexed */
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 autoIndex; /* True if is automatically created (ex: by UNIQUE) */
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};
2N/A
2N/A/*
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**
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*/
2N/Astruct Token {
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};
2N/A
2N/A/*
2N/A** Each node of an expression in the parse tree is an instance
2N/A** of this structure.
2N/A**
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** tree.
2N/A**
2N/A** Expr.pRight and Expr.pLeft are subexpressions. Expr.pList is a list
2N/A** of argument if the expression is a function.
2N/A**
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** a compound token.
2N/A**
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**
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**
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** operand.
2N/A*/
2N/Astruct Expr {
2N/A u8 op; /* Operation performed by this node */
2N/A u8 dataType; /* Either SQLITE_SO_TEXT or SQLITE_SO_NUM */
2N/A u8 iDb; /* Database referenced by this expression */
2N/A u8 flags; /* Various flags. See below */
2N/A Expr *pLeft, *pRight; /* Left and right subnodes */
2N/A ExprList *pList; /* A list of expressions used as function arguments
2N/A ** or in "<expr> IN (<expr-list)" */
2N/A Token token; /* An operand token */
2N/A Token span; /* Complete text of the expression */
2N/A int iTable, iColumn; /* When op==TK_COLUMN, then this expr node means the
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 Select *pSelect; /* When the expression is a sub-select. Also the
2N/A ** right side of "<expr> IN (<select>)" */
2N/A};
2N/A
2N/A/*
2N/A** The following are the meanings of bits in the Expr.flags field.
2N/A*/
2N/A#define EP_FromJoin 0x0001 /* Originated in ON or USING clause of a join */
2N/A
2N/A/*
2N/A** These macros can be used to test, set, or clear bits in the
2N/A** Expr.flags field.
2N/A*/
2N/A#define ExprHasProperty(E,P) (((E)->flags&(P))==(P))
2N/A#define ExprHasAnyProperty(E,P) (((E)->flags&(P))!=0)
2N/A#define ExprSetProperty(E,P) (E)->flags|=(P)
2N/A#define ExprClearProperty(E,P) (E)->flags&=~(P)
2N/A
2N/A/*
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*/
2N/Astruct ExprList {
2N/A int nExpr; /* Number of expressions on the list */
2N/A int nAlloc; /* Number of entries allocated below */
2N/A struct ExprList_item {
2N/A Expr *pExpr; /* The list of expressions */
2N/A char *zName; /* Token associated with this expression */
2N/A u8 sortOrder; /* 1 for DESC or 0 for ASC */
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};
2N/A
2N/A/*
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**
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**
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**
2N/A** INSERT INTO t(a,b,c) ...
2N/A**
2N/A** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
2N/A*/
2N/Astruct IdList {
2N/A int nId; /* Number of identifiers on the list */
2N/A int nAlloc; /* Number of entries allocated for a[] below */
2N/A struct IdList_item {
2N/A char *zName; /* Name of the identifier */
2N/A int idx; /* Index in some Table.aCol[] of a column named zName */
2N/A } *a;
2N/A};
2N/A
2N/A/*
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**
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*/
2N/Astruct SrcList {
2N/A i16 nSrc; /* Number of tables or subqueries in the FROM clause */
2N/A i16 nAlloc; /* Number of entries allocated in a[] below */
2N/A struct SrcList_item {
2N/A char *zDatabase; /* Name of database holding this table */
2N/A char *zName; /* Name of the table */
2N/A char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
2N/A Table *pTab; /* An SQL table corresponding to zName */
2N/A Select *pSelect; /* A SELECT statement used in place of a table name */
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 Expr *pOn; /* The ON clause of a join */
2N/A IdList *pUsing; /* The USING clause of a join */
2N/A } a[1]; /* One entry for each identifier on the list */
2N/A};
2N/A
2N/A/*
2N/A** Permitted values of the SrcList.a.jointype field
2N/A*/
2N/A#define JT_INNER 0x0001 /* Any kind of inner or cross join */
2N/A#define JT_NATURAL 0x0002 /* True for a "natural" join */
2N/A#define JT_LEFT 0x0004 /* Left outer join */
2N/A#define JT_RIGHT 0x0008 /* Right outer 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
2N/A/*
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*/
2N/Astruct WhereLevel {
2N/A int iMem; /* Memory cell used by this level */
2N/A Index *pIdx; /* Index used */
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 inOp, inP1, inP2;/* Opcode used to implement an IN operator */
2N/A int bRev; /* Do the scan in the reverse direction */
2N/A};
2N/A
2N/A/*
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*/
2N/Astruct WhereInfo {
2N/A Parse *pParse;
2N/A SrcList *pTabList; /* List of tables in the join */
2N/A int iContinue; /* Jump here to continue with next record */
2N/A int iBreak; /* Jump here to break out of the loop */
2N/A int nLevel; /* Number of nested 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};
2N/A
2N/A/*
2N/A** An instance of the following structure contains all information
2N/A** needed to generate code for a single SELECT statement.
2N/A**
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**
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*/
2N/Astruct Select {
2N/A ExprList *pEList; /* The fields of the result */
2N/A u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
2N/A u8 isDistinct; /* True if the DISTINCT keyword is present */
2N/A SrcList *pSrc; /* The FROM clause */
2N/A Expr *pWhere; /* The WHERE clause */
2N/A ExprList *pGroupBy; /* The GROUP BY clause */
2N/A Expr *pHaving; /* The HAVING clause */
2N/A ExprList *pOrderBy; /* The ORDER BY clause */
2N/A Select *pPrior; /* Prior select in a compound select statement */
2N/A int nLimit, nOffset; /* LIMIT and OFFSET values. -1 means not used */
2N/A int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
2N/A char *zSelect; /* Complete text of the SELECT command */
2N/A};
2N/A
2N/A/*
2N/A** The results of a select can be distributed in several ways.
2N/A*/
2N/A#define SRT_Callback 1 /* Invoke a callback with each row of result */
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_Union 5 /* Store result as keys in a table */
2N/A#define SRT_Except 6 /* Remove result from a UNION table */
2N/A#define SRT_Table 7 /* Store result as data with a unique key */
2N/A#define SRT_TempTable 8 /* Store result in a trasient table */
2N/A#define SRT_Discard 9 /* Do not save the results anywhere */
2N/A#define SRT_Sorter 10 /* Store results in the sorter */
2N/A#define SRT_Subroutine 11 /* Call a subroutine to handle results */
2N/A
2N/A/*
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** expressions.
2N/A**
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**
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**
2N/A** If AggExpr.pExpr==0, that means the expression is "count(*)".
2N/A*/
2N/Astruct AggExpr {
2N/A int isAgg; /* if TRUE contains an aggregate function */
2N/A Expr *pExpr; /* The expression */
2N/A FuncDef *pFunc; /* Information about the aggregate function */
2N/A};
2N/A
2N/A/*
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*/
2N/Astruct Parse {
2N/A sqlite *db; /* The main database structure */
2N/A int rc; /* Return code from execution */
2N/A char *zErrMsg; /* An error message */
2N/A Token sErrToken; /* The token at which the error occurred */
2N/A Token sFirstToken; /* The first token parsed */
2N/A Token sLastToken; /* The last token parsed */
2N/A const char *zTail; /* All SQL text past the last semicolon parsed */
2N/A Table *pNewTable; /* A table being constructed by CREATE TABLE */
2N/A Vdbe *pVdbe; /* An engine for executing database bytecode */
2N/A u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */
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 AggExpr *aAgg; /* An array of aggregate expressions */
2N/A const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
2N/A Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
2N/A TriggerStack *trigStack; /* Trigger actions being coded */
2N/A};
2N/A
2N/A/*
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*/
2N/Astruct AuthContext {
2N/A const char *zAuthContext; /* Put saved Parse.zAuthContext here */
2N/A Parse *pParse; /* The Parse structure */
2N/A};
2N/A
2N/A/*
2N/A** Bitfield flags for P2 value in OP_PutIntKey and OP_Delete
2N/A*/
2N/A#define OPFLAG_NCHANGE 1 /* Set to update db->nChange */
2N/A#define OPFLAG_LASTROWID 2 /* Set to update db->lastRowid */
2N/A#define OPFLAG_CSCHANGE 4 /* Set to update db->csChange */
2N/A
2N/A/*
2N/A * Each trigger present in the database schema is stored as an instance of
2N/A * struct Trigger.
2N/A *
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 * struct Table.
2N/A *
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 */
2N/Astruct Trigger {
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 iTabDb; /* Database containing Trigger.table */
2N/A u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */
2N/A u8 tr_tm; /* One of TK_BEFORE, TK_AFTER */
2N/A Expr *pWhen; /* The WHEN clause of the expresion (may be NULL) */
2N/A IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger,
2N/A the <column-list> is stored here */
2N/A int foreach; /* One of TK_ROW or TK_STATEMENT */
2N/A Token nameToken; /* Token containing zName. Use during parsing only */
2N/A
2N/A TriggerStep *step_list; /* Link list of trigger program steps */
2N/A Trigger *pNext; /* Next trigger associated with the table */
2N/A};
2N/A
2N/A/*
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 *
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 *
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 *
2N/A * (op == TK_INSERT)
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 * inserted into.
2N/A *
2N/A * (op == TK_DELETE)
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 * Otherwise NULL.
2N/A *
2N/A * (op == TK_UPDATE)
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 * Otherwise NULL.
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 * argument.
2N/A *
2N/A */
2N/Astruct TriggerStep {
2N/A int op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
2N/A int orconf; /* OE_Rollback etc. */
2N/A Trigger *pTrig; /* The trigger that this step is a part of */
2N/A
2N/A Select *pSelect; /* Valid for SELECT and sometimes
2N/A INSERT steps (when pExprList == 0) */
2N/A Token target; /* Valid for DELETE, UPDATE, INSERT steps */
2N/A Expr *pWhere; /* Valid for DELETE, UPDATE steps */
2N/A ExprList *pExprList; /* Valid for UPDATE statements and sometimes
2N/A INSERT steps (when pSelect == 0) */
2N/A IdList *pIdList; /* Valid for INSERT statements only */
2N/A
2N/A TriggerStep * pNext; /* Next in the link-list */
2N/A};
2N/A
2N/A/*
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 *
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 *
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 *
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 *
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 */
2N/Astruct TriggerStack {
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 int orconf; /* Current orconf policy */
2N/A int ignoreJump; /* where to jump to for a RAISE(IGNORE) */
2N/A Trigger *pTrigger; /* The trigger currently being coded */
2N/A TriggerStack *pNext; /* Next trigger down on the trigger stack */
2N/A};
2N/A
2N/A/*
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** explicit.
2N/A*/
2N/Atypedef struct DbFixer DbFixer;
2N/Astruct DbFixer {
2N/A Parse *pParse; /* The parsing context. Error messages written here */
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};
2N/A
2N/A/*
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 */
2N/Aextern int always_code_trigger_setup;
2N/A
2N/A/*
2N/A** Internal function prototypes
2N/A*/
2N/Aint sqliteStrICmp(const char *, const char *);
2N/Aint sqliteStrNICmp(const char *, const char *, int);
2N/Aint sqliteHashNoCase(const char *, int);
2N/Aint sqliteIsNumber(const char*);
2N/Aint sqliteCompare(const char *, const char *);
2N/Aint sqliteSortCompare(const char *, const char *);
2N/Avoid sqliteRealToSortable(double r, char *);
2N/A#ifdef MEMORY_DEBUG
2N/A void *sqliteMalloc_(int,int,char*,int);
2N/A void sqliteFree_(void*,char*,int);
2N/A void *sqliteRealloc_(void*,int,char*,int);
2N/A char *sqliteStrDup_(const char*,char*,int);
2N/A char *sqliteStrNDup_(const char*, int,char*,int);
2N/A void sqliteCheckMemory(void*,int);
2N/A#else
2N/A void *sqliteMalloc(int);
2N/A void *sqliteMallocRaw(int);
2N/A void sqliteFree(void*);
2N/A void *sqliteRealloc(void*,int);
2N/A char *sqliteStrDup(const char*);
2N/A char *sqliteStrNDup(const char*, int);
2N/A# define sqliteCheckMemory(a,b)
2N/A#endif
2N/Achar *sqliteMPrintf(const char*, ...);
2N/Achar *sqliteVMPrintf(const char*, va_list);
2N/Avoid sqliteSetString(char **, const char *, ...);
2N/Avoid sqliteSetNString(char **, ...);
2N/Avoid sqliteErrorMsg(Parse*, const char*, ...);
2N/Avoid sqliteDequote(char*);
2N/Aint sqliteKeywordCode(const char*, int);
2N/Aint sqliteRunParser(Parse*, const char*, char **);
2N/Avoid sqliteExec(Parse*);
2N/AExpr *sqliteExpr(int, Expr*, Expr*, Token*);
2N/Avoid sqliteExprSpan(Expr*,Token*,Token*);
2N/AExpr *sqliteExprFunction(ExprList*, Token*);
2N/Avoid sqliteExprDelete(Expr*);
2N/AExprList *sqliteExprListAppend(ExprList*,Expr*,Token*);
2N/Avoid sqliteExprListDelete(ExprList*);
2N/Aint sqliteInit(sqlite*, char**);
2N/Avoid sqlitePragma(Parse*,Token*,Token*,int);
2N/Avoid sqliteResetInternalSchema(sqlite*, int);
2N/Avoid sqliteBeginParse(Parse*,int);
2N/Avoid sqliteRollbackInternalChanges(sqlite*);
2N/Avoid sqliteCommitInternalChanges(sqlite*);
2N/ATable *sqliteResultSetOfSelect(Parse*,char*,Select*);
2N/Avoid sqliteOpenMasterTable(Vdbe *v, int);
2N/Avoid sqliteStartTable(Parse*,Token*,Token*,int,int);
2N/Avoid sqliteAddColumn(Parse*,Token*);
2N/Avoid sqliteAddNotNull(Parse*, int);
2N/Avoid sqliteAddPrimaryKey(Parse*, IdList*, int);
2N/Avoid sqliteAddColumnType(Parse*,Token*,Token*);
2N/Avoid sqliteAddDefaultValue(Parse*,Token*,int);
2N/Aint sqliteCollateType(const char*, int);
2N/Avoid sqliteAddCollateType(Parse*, int);
2N/Avoid sqliteEndTable(Parse*,Token*,Select*);
2N/Avoid sqliteCreateView(Parse*,Token*,Token*,Select*,int);
2N/Aint sqliteViewGetColumnNames(Parse*,Table*);
2N/Avoid sqliteDropTable(Parse*, Token*, int);
2N/Avoid sqliteDeleteTable(sqlite*, Table*);
2N/Avoid sqliteInsert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
2N/AIdList *sqliteIdListAppend(IdList*, Token*);
2N/Aint sqliteIdListIndex(IdList*,const char*);
2N/ASrcList *sqliteSrcListAppend(SrcList*, Token*, Token*);
2N/Avoid sqliteSrcListAddAlias(SrcList*, Token*);
2N/Avoid sqliteSrcListAssignCursors(Parse*, SrcList*);
2N/Avoid sqliteIdListDelete(IdList*);
2N/Avoid sqliteSrcListDelete(SrcList*);
2N/Avoid sqliteCreateIndex(Parse*,Token*,SrcList*,IdList*,int,Token*,Token*);
2N/Avoid sqliteDropIndex(Parse*, SrcList*);
2N/Avoid sqliteAddKeyType(Vdbe*, ExprList*);
2N/Avoid sqliteAddIdxKeyType(Vdbe*, Index*);
2N/Aint sqliteSelect(Parse*, Select*, int, int, Select*, int, int*);
2N/ASelect *sqliteSelectNew(ExprList*,SrcList*,Expr*,ExprList*,Expr*,ExprList*,
2N/A int,int,int);
2N/Avoid sqliteSelectDelete(Select*);
2N/Avoid sqliteSelectUnbind(Select*);
2N/ATable *sqliteSrcListLookup(Parse*, SrcList*);
2N/Aint sqliteIsReadOnly(Parse*, Table*, int);
2N/Avoid sqliteDeleteFrom(Parse*, SrcList*, Expr*);
2N/Avoid sqliteUpdate(Parse*, SrcList*, ExprList*, Expr*, int);
2N/AWhereInfo *sqliteWhereBegin(Parse*, SrcList*, Expr*, int, ExprList**);
2N/Avoid sqliteWhereEnd(WhereInfo*);
2N/Avoid sqliteExprCode(Parse*, Expr*);
2N/Aint sqliteExprCodeExprList(Parse*, ExprList*, int);
2N/Avoid sqliteExprIfTrue(Parse*, Expr*, int, int);
2N/Avoid sqliteExprIfFalse(Parse*, Expr*, int, int);
2N/ATable *sqliteFindTable(sqlite*,const char*, const char*);
2N/ATable *sqliteLocateTable(Parse*,const char*, const char*);
2N/AIndex *sqliteFindIndex(sqlite*,const char*, const char*);
2N/Avoid sqliteUnlinkAndDeleteIndex(sqlite*,Index*);
2N/Avoid sqliteCopy(Parse*, SrcList*, Token*, Token*, int);
2N/Avoid sqliteVacuum(Parse*, Token*);
2N/Aint sqliteRunVacuum(char**, sqlite*);
2N/Aint sqliteGlobCompare(const unsigned char*,const unsigned char*);
2N/Aint sqliteLikeCompare(const unsigned char*,const unsigned char*);
2N/Achar *sqliteTableNameFromToken(Token*);
2N/Aint sqliteExprCheck(Parse*, Expr*, int, int*);
2N/Aint sqliteExprType(Expr*);
2N/Aint sqliteExprCompare(Expr*, Expr*);
2N/Aint sqliteFuncId(Token*);
2N/Aint sqliteExprResolveIds(Parse*, SrcList*, ExprList*, Expr*);
2N/Aint sqliteExprAnalyzeAggregates(Parse*, Expr*);
2N/AVdbe *sqliteGetVdbe(Parse*);
2N/Avoid sqliteRandomness(int, void*);
2N/Avoid sqliteRollbackAll(sqlite*);
2N/Avoid sqliteCodeVerifySchema(Parse*, int);
2N/Avoid sqliteBeginTransaction(Parse*, int);
2N/Avoid sqliteCommitTransaction(Parse*);
2N/Avoid sqliteRollbackTransaction(Parse*);
2N/Aint sqliteExprIsConstant(Expr*);
2N/Aint sqliteExprIsInteger(Expr*, int*);
2N/Aint sqliteIsRowid(const char*);
2N/Avoid sqliteGenerateRowDelete(sqlite*, Vdbe*, Table*, int, int);
2N/Avoid sqliteGenerateRowIndexDelete(sqlite*, Vdbe*, Table*, int, char*);
2N/Avoid sqliteGenerateConstraintChecks(Parse*,Table*,int,char*,int,int,int,int);
2N/Avoid sqliteCompleteInsertion(Parse*, Table*, int, char*, int, int, int);
2N/Aint sqliteOpenTableAndIndices(Parse*, Table*, int);
2N/Avoid sqliteBeginWriteOperation(Parse*, int, int);
2N/Avoid sqliteEndWriteOperation(Parse*);
2N/AExpr *sqliteExprDup(Expr*);
2N/Avoid sqliteTokenCopy(Token*, Token*);
2N/AExprList *sqliteExprListDup(ExprList*);
2N/ASrcList *sqliteSrcListDup(SrcList*);
2N/AIdList *sqliteIdListDup(IdList*);
2N/ASelect *sqliteSelectDup(Select*);
2N/AFuncDef *sqliteFindFunction(sqlite*,const char*,int,int,int);
2N/Avoid sqliteRegisterBuiltinFunctions(sqlite*);
2N/Avoid sqliteRegisterDateTimeFunctions(sqlite*);
2N/Aint sqliteSafetyOn(sqlite*);
2N/Aint sqliteSafetyOff(sqlite*);
2N/Aint sqliteSafetyCheck(sqlite*);
2N/Avoid sqliteChangeCookie(sqlite*, Vdbe*);
2N/Avoid sqliteBeginTrigger(Parse*, Token*,int,int,IdList*,SrcList*,int,Expr*,int);
2N/Avoid sqliteFinishTrigger(Parse*, TriggerStep*, Token*);
2N/Avoid sqliteDropTrigger(Parse*, SrcList*);
2N/Avoid sqliteDropTriggerPtr(Parse*, Trigger*, int);
2N/Aint sqliteTriggersExist(Parse* , Trigger* , int , int , int, ExprList*);
2N/Aint sqliteCodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int,
2N/A int, int);
2N/Avoid sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
2N/Avoid sqliteDeleteTriggerStep(TriggerStep*);
2N/ATriggerStep *sqliteTriggerSelectStep(Select*);
2N/ATriggerStep *sqliteTriggerInsertStep(Token*, IdList*, ExprList*, Select*, int);
2N/ATriggerStep *sqliteTriggerUpdateStep(Token*, ExprList*, Expr*, int);
2N/ATriggerStep *sqliteTriggerDeleteStep(Token*, Expr*);
2N/Avoid sqliteDeleteTrigger(Trigger*);
2N/Aint sqliteJoinType(Parse*, Token*, Token*, Token*);
2N/Avoid sqliteCreateForeignKey(Parse*, IdList*, Token*, IdList*, int);
2N/Avoid sqliteDeferForeignKey(Parse*, int);
2N/A#ifndef SQLITE_OMIT_AUTHORIZATION
2N/A void sqliteAuthRead(Parse*,Expr*,SrcList*);
2N/A int sqliteAuthCheck(Parse*,int, const char*, const char*, const char*);
2N/A void sqliteAuthContextPush(Parse*, AuthContext*, const char*);
2N/A void sqliteAuthContextPop(AuthContext*);
2N/A#else
2N/A# define sqliteAuthRead(a,b,c)
2N/A# define sqliteAuthCheck(a,b,c,d,e) SQLITE_OK
2N/A# define sqliteAuthContextPush(a,b,c)
2N/A# define sqliteAuthContextPop(a) ((void)(a))
2N/A#endif
2N/Avoid sqliteAttach(Parse*, Token*, Token*, Token*);
2N/Avoid sqliteDetach(Parse*, Token*);
2N/Aint sqliteBtreeFactory(const sqlite *db, const char *zFilename,
2N/A int mode, int nPg, Btree **ppBtree);
2N/Aint sqliteFixInit(DbFixer*, Parse*, int, const char*, const Token*);
2N/Aint sqliteFixSrcList(DbFixer*, SrcList*);
2N/Aint sqliteFixSelect(DbFixer*, Select*);
2N/Aint sqliteFixExpr(DbFixer*, Expr*);
2N/Aint sqliteFixExprList(DbFixer*, ExprList*);
2N/Aint sqliteFixTriggerStep(DbFixer*, TriggerStep*);
2N/Adouble sqliteAtoF(const char *z, const char **);
2N/Achar *sqlite_snprintf(int,char*,const char*,...);
2N/Aint sqliteFitsIn32Bits(const char *);