ds@1952: /* ds@1952: ** 2001 September 15 ds@1952: ** ds@1952: ** The author disclaims copyright to this source code. In place of ds@1952: ** a legal notice, here is a blessing: ds@1952: ** ds@1952: ** May you do good and not evil. ds@1952: ** May you find forgiveness for yourself and forgive others. ds@1952: ** May you share freely, never taking more than you give. ds@1952: ** ds@1952: ************************************************************************* ds@1952: ** Internal interface definitions for SQLite. ds@1952: ** ds@1952: ** @(#) $Id$ ds@1952: */ ds@1952: #ifndef _SQLITEINT_H_ ds@1952: #define _SQLITEINT_H_ ds@1952: #include "sqliteLimit.h" ds@1952: ds@1952: /* ds@1952: ** For testing purposes, the various size limit constants are really ds@1952: ** variables that we can modify in the testfixture. ds@1952: */ ds@1952: #ifdef SQLITE_TEST ds@1952: #undef SQLITE_MAX_LENGTH ds@1952: #undef SQLITE_MAX_COLUMN ds@1952: #undef SQLITE_MAX_SQL_LENGTH ds@1952: #undef SQLITE_MAX_EXPR_DEPTH ds@1952: #undef SQLITE_MAX_COMPOUND_SELECT ds@1952: #undef SQLITE_MAX_VDBE_OP ds@1952: #undef SQLITE_MAX_FUNCTION_ARG ds@1952: #undef SQLITE_MAX_VARIABLE_NUMBER ds@1952: #undef SQLITE_MAX_PAGE_SIZE ds@1952: #undef SQLITE_MAX_PAGE_COUNT ds@1952: #undef SQLITE_MAX_LIKE_PATTERN_LENGTH ds@1952: ds@1952: #define SQLITE_MAX_LENGTH sqlite3MAX_LENGTH ds@1952: #define SQLITE_MAX_COLUMN sqlite3MAX_COLUMN ds@1952: #define SQLITE_MAX_SQL_LENGTH sqlite3MAX_SQL_LENGTH ds@1952: #define SQLITE_MAX_EXPR_DEPTH sqlite3MAX_EXPR_DEPTH ds@1952: #define SQLITE_MAX_COMPOUND_SELECT sqlite3MAX_COMPOUND_SELECT ds@1952: #define SQLITE_MAX_VDBE_OP sqlite3MAX_VDBE_OP ds@1952: #define SQLITE_MAX_FUNCTION_ARG sqlite3MAX_FUNCTION_ARG ds@1952: #define SQLITE_MAX_VARIABLE_NUMBER sqlite3MAX_VARIABLE_NUMBER ds@1952: #define SQLITE_MAX_PAGE_SIZE sqlite3MAX_PAGE_SIZE ds@1952: #define SQLITE_MAX_PAGE_COUNT sqlite3MAX_PAGE_COUNT ds@1952: #define SQLITE_MAX_LIKE_PATTERN_LENGTH sqlite3MAX_LIKE_PATTERN_LENGTH ds@1952: ds@1952: extern int sqlite3MAX_LENGTH; ds@1952: extern int sqlite3MAX_COLUMN; ds@1952: extern int sqlite3MAX_SQL_LENGTH; ds@1952: extern int sqlite3MAX_EXPR_DEPTH; ds@1952: extern int sqlite3MAX_COMPOUND_SELECT; ds@1952: extern int sqlite3MAX_VDBE_OP; ds@1952: extern int sqlite3MAX_FUNCTION_ARG; ds@1952: extern int sqlite3MAX_VARIABLE_NUMBER; ds@1952: extern int sqlite3MAX_PAGE_SIZE; ds@1952: extern int sqlite3MAX_PAGE_COUNT; ds@1952: extern int sqlite3MAX_LIKE_PATTERN_LENGTH; ds@1952: #endif ds@1952: ds@1952: ds@1952: /* ds@1952: ** The SQLITE_THREADSAFE macro must be defined as either 0 or 1. ds@1952: ** Older versions of SQLite used an optional THREADSAFE macro. ds@1952: ** We support that for legacy ds@1952: */ ds@1952: #if !defined(SQLITE_THREADSAFE) ds@1952: #if defined(THREADSAFE) ds@1952: # define SQLITE_THREADSAFE THREADSAFE ds@1952: #else ds@1952: # define SQLITE_THREADSAFE 1 ds@1952: #endif ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** We need to define _XOPEN_SOURCE as follows in order to enable ds@1952: ** recursive mutexes on most unix systems. But Mac OS X is different. ds@1952: ** The _XOPEN_SOURCE define causes problems for Mac OS X we are told, ds@1952: ** so it is omitted there. See ticket #2673. ds@1952: ** ds@1952: ** Later we learn that _XOPEN_SOURCE is poorly or incorrectly ds@1952: ** implemented on some systems. So we avoid defining it at all ds@1952: ** if it is already defined or if it is unneeded because we are ds@1952: ** not doing a threadsafe build. Ticket #2681. ds@1952: */ ds@1952: #if !defined(_XOPEN_SOURCE) && !defined(__MACOS__) && SQLITE_THREADSAFE ds@1952: # define _XOPEN_SOURCE 500 /* Needed to enable pthread recursive mutexes */ ds@1952: #endif ds@1952: ds@1952: #if defined(SQLITE_TCL) || defined(TCLSH) ds@1952: # include ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** Many people are failing to set -DNDEBUG=1 when compiling SQLite. ds@1952: ** Setting NDEBUG makes the code smaller and run faster. So the following ds@1952: ** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1 ds@1952: ** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out ds@1952: ** feature. ds@1952: */ ds@1952: #if !defined(NDEBUG) && !defined(SQLITE_DEBUG) ds@1952: # define NDEBUG 1 ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** These #defines should enable >2GB file support on Posix if the ds@1952: ** underlying operating system supports it. If the OS lacks ds@1952: ** large file support, or if the OS is windows, these should be no-ops. ds@1952: ** ds@1952: ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch ds@1952: ** on the compiler command line. This is necessary if you are compiling ds@1952: ** on a recent machine (ex: RedHat 7.2) but you want your code to work ds@1952: ** on an older machine (ex: RedHat 6.0). If you compile on RedHat 7.2 ds@1952: ** without this option, LFS is enable. But LFS does not exist in the kernel ds@1952: ** in RedHat 6.0, so the code won't work. Hence, for maximum binary ds@1952: ** portability you should omit LFS. ds@1952: ** ds@1952: ** Similar is true for MacOS. LFS is only supported on MacOS 9 and later. ds@1952: */ ds@1952: #ifndef SQLITE_DISABLE_LFS ds@1952: # define _LARGE_FILE 1 ds@1952: # ifndef _FILE_OFFSET_BITS ds@1952: # define _FILE_OFFSET_BITS 64 ds@1952: # endif ds@1952: # define _LARGEFILE_SOURCE 1 ds@1952: #endif ds@1952: ds@1952: #include "sqlite3.h" ds@1952: #include "hash.h" ds@1952: #include "parse.h" ds@1952: #include ds@1952: #include ds@1952: #include ds@1952: #include ds@1952: #include ds@1952: ds@1952: #define sqlite3_isnan(X) ((X)!=(X)) ds@1952: ds@1952: /* ds@1952: ** If compiling for a processor that lacks floating point support, ds@1952: ** substitute integer for floating-point ds@1952: */ ds@1952: #ifdef SQLITE_OMIT_FLOATING_POINT ds@1952: # define double sqlite_int64 ds@1952: # define LONGDOUBLE_TYPE sqlite_int64 ds@1952: # ifndef SQLITE_BIG_DBL ds@1952: # define SQLITE_BIG_DBL (0x7fffffffffffffff) ds@1952: # endif ds@1952: # define SQLITE_OMIT_DATETIME_FUNCS 1 ds@1952: # define SQLITE_OMIT_TRACE 1 ds@1952: # undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT ds@1952: #endif ds@1952: #ifndef SQLITE_BIG_DBL ds@1952: # define SQLITE_BIG_DBL (1e99) ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0 ds@1952: ** afterward. Having this macro allows us to cause the C compiler ds@1952: ** to omit code used by TEMP tables without messy #ifndef statements. ds@1952: */ ds@1952: #ifdef SQLITE_OMIT_TEMPDB ds@1952: #define OMIT_TEMPDB 1 ds@1952: #else ds@1952: #define OMIT_TEMPDB 0 ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** If the following macro is set to 1, then NULL values are considered ds@1952: ** distinct when determining whether or not two entries are the same ds@1952: ** in a UNIQUE index. This is the way PostgreSQL, Oracle, DB2, MySQL, ds@1952: ** OCELOT, and Firebird all work. The SQL92 spec explicitly says this ds@1952: ** is the way things are suppose to work. ds@1952: ** ds@1952: ** If the following macro is set to 0, the NULLs are indistinct for ds@1952: ** a UNIQUE index. In this mode, you can only have a single NULL entry ds@1952: ** for a column declared UNIQUE. This is the way Informix and SQL Server ds@1952: ** work. ds@1952: */ ds@1952: #define NULL_DISTINCT_FOR_UNIQUE 1 ds@1952: ds@1952: /* ds@1952: ** The "file format" number is an integer that is incremented whenever ds@1952: ** the VDBE-level file format changes. The following macros define the ds@1952: ** the default file format for new databases and the maximum file format ds@1952: ** that the library can read. ds@1952: */ ds@1952: #define SQLITE_MAX_FILE_FORMAT 4 ds@1952: #ifndef SQLITE_DEFAULT_FILE_FORMAT ds@1952: # define SQLITE_DEFAULT_FILE_FORMAT 1 ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** Provide a default value for TEMP_STORE in case it is not specified ds@1952: ** on the command-line ds@1952: */ ds@1952: #ifndef TEMP_STORE ds@1952: # define TEMP_STORE 1 ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** GCC does not define the offsetof() macro so we'll have to do it ds@1952: ** ourselves. ds@1952: */ ds@1952: #ifndef offsetof ds@1952: #define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD)) ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** Check to see if this machine uses EBCDIC. (Yes, believe it or ds@1952: ** not, there are still machines out there that use EBCDIC.) ds@1952: */ ds@1952: #if 'A' == '\301' ds@1952: # define SQLITE_EBCDIC 1 ds@1952: #else ds@1952: # define SQLITE_ASCII 1 ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** Integers of known sizes. These typedefs might change for architectures ds@1952: ** where the sizes very. Preprocessor macros are available so that the ds@1952: ** types can be conveniently redefined at compile-type. Like this: ds@1952: ** ds@1952: ** cc '-DUINTPTR_TYPE=long long int' ... ds@1952: */ ds@1952: #ifndef UINT32_TYPE ds@1952: # define UINT32_TYPE unsigned int ds@1952: #endif ds@1952: #ifndef UINT16_TYPE ds@1952: # define UINT16_TYPE unsigned short int ds@1952: #endif ds@1952: #ifndef INT16_TYPE ds@1952: # define INT16_TYPE short int ds@1952: #endif ds@1952: #ifndef UINT8_TYPE ds@1952: # define UINT8_TYPE unsigned char ds@1952: #endif ds@1952: #ifndef INT8_TYPE ds@1952: # define INT8_TYPE signed char ds@1952: #endif ds@1952: #ifndef LONGDOUBLE_TYPE ds@1952: # define LONGDOUBLE_TYPE long double ds@1952: #endif ds@1952: typedef sqlite_int64 i64; /* 8-byte signed integer */ ds@1952: typedef sqlite_uint64 u64; /* 8-byte unsigned integer */ ds@1952: typedef UINT32_TYPE u32; /* 4-byte unsigned integer */ ds@1952: typedef UINT16_TYPE u16; /* 2-byte unsigned integer */ ds@1952: typedef INT16_TYPE i16; /* 2-byte signed integer */ ds@1952: typedef UINT8_TYPE u8; /* 1-byte unsigned integer */ ds@1952: typedef UINT8_TYPE i8; /* 1-byte signed integer */ ds@1952: ds@1952: /* ds@1952: ** Macros to determine whether the machine is big or little endian, ds@1952: ** evaluated at runtime. ds@1952: */ ds@1952: #ifdef SQLITE_AMALGAMATION ds@1952: const int sqlite3One; ds@1952: #else ds@1952: extern const int sqlite3one; ds@1952: #endif ds@1952: #if defined(i386) || defined(__i386__) || defined(_M_IX86) ds@1952: # define SQLITE_BIGENDIAN 0 ds@1952: # define SQLITE_LITTLEENDIAN 1 ds@1952: # define SQLITE_UTF16NATIVE SQLITE_UTF16LE ds@1952: #else ds@1952: # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0) ds@1952: # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1) ds@1952: # define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE) ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** An instance of the following structure is used to store the busy-handler ds@1952: ** callback for a given sqlite handle. ds@1952: ** ds@1952: ** The sqlite.busyHandler member of the sqlite struct contains the busy ds@1952: ** callback for the database handle. Each pager opened via the sqlite ds@1952: ** handle is passed a pointer to sqlite.busyHandler. The busy-handler ds@1952: ** callback is currently invoked only from within pager.c. ds@1952: */ ds@1952: typedef struct BusyHandler BusyHandler; ds@1952: struct BusyHandler { ds@1952: int (*xFunc)(void *,int); /* The busy callback */ ds@1952: void *pArg; /* First arg to busy callback */ ds@1952: int nBusy; /* Incremented with each busy call */ ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** Defer sourcing vdbe.h and btree.h until after the "u8" and ds@1952: ** "BusyHandler typedefs. ds@1952: */ ds@1952: #include "btree.h" ds@1952: #include "vdbe.h" ds@1952: #include "pager.h" ds@1952: ds@1952: ds@1952: /* ds@1952: ** Name of the master database table. The master database table ds@1952: ** is a special table that holds the names and attributes of all ds@1952: ** user tables and indices. ds@1952: */ ds@1952: #define MASTER_NAME "sqlite_master" ds@1952: #define TEMP_MASTER_NAME "sqlite_temp_master" ds@1952: ds@1952: /* ds@1952: ** The root-page of the master database table. ds@1952: */ ds@1952: #define MASTER_ROOT 1 ds@1952: ds@1952: /* ds@1952: ** The name of the schema table. ds@1952: */ ds@1952: #define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME) ds@1952: ds@1952: /* ds@1952: ** A convenience macro that returns the number of elements in ds@1952: ** an array. ds@1952: */ ds@1952: #define ArraySize(X) (sizeof(X)/sizeof(X[0])) ds@1952: ds@1952: /* ds@1952: ** Forward references to structures ds@1952: */ ds@1952: typedef struct AggInfo AggInfo; ds@1952: typedef struct AuthContext AuthContext; ds@1952: typedef struct CollSeq CollSeq; ds@1952: typedef struct Column Column; ds@1952: typedef struct Db Db; ds@1952: typedef struct Schema Schema; ds@1952: typedef struct Expr Expr; ds@1952: typedef struct ExprList ExprList; ds@1952: typedef struct FKey FKey; ds@1952: typedef struct FuncDef FuncDef; ds@1952: typedef struct IdList IdList; ds@1952: typedef struct Index Index; ds@1952: typedef struct KeyClass KeyClass; ds@1952: typedef struct KeyInfo KeyInfo; ds@1952: typedef struct Module Module; ds@1952: typedef struct NameContext NameContext; ds@1952: typedef struct Parse Parse; ds@1952: typedef struct Select Select; ds@1952: typedef struct SrcList SrcList; ds@1952: typedef struct Table Table; ds@1952: typedef struct TableLock TableLock; ds@1952: typedef struct Token Token; ds@1952: typedef struct TriggerStack TriggerStack; ds@1952: typedef struct TriggerStep TriggerStep; ds@1952: typedef struct Trigger Trigger; ds@1952: typedef struct WhereInfo WhereInfo; ds@1952: typedef struct WhereLevel WhereLevel; ds@1952: ds@1952: #include "os.h" ds@1952: #include "mutex.h" ds@1952: ds@1952: /* ds@1952: ** Each database file to be accessed by the system is an instance ds@1952: ** of the following structure. There are normally two of these structures ds@1952: ** in the sqlite.aDb[] array. aDb[0] is the main database file and ds@1952: ** aDb[1] is the database file used to hold temporary tables. Additional ds@1952: ** databases may be attached. ds@1952: */ ds@1952: struct Db { ds@1952: char *zName; /* Name of this database */ ds@1952: Btree *pBt; /* The B*Tree structure for this database file */ ds@1952: u8 inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */ ds@1952: u8 safety_level; /* How aggressive at synching data to disk */ ds@1952: void *pAux; /* Auxiliary data. Usually NULL */ ds@1952: void (*xFreeAux)(void*); /* Routine to free pAux */ ds@1952: Schema *pSchema; /* Pointer to database schema (possibly shared) */ ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** An instance of the following structure stores a database schema. ds@1952: ** ds@1952: ** If there are no virtual tables configured in this schema, the ds@1952: ** Schema.db variable is set to NULL. After the first virtual table ds@1952: ** has been added, it is set to point to the database connection ds@1952: ** used to create the connection. Once a virtual table has been ds@1952: ** added to the Schema structure and the Schema.db variable populated, ds@1952: ** only that database connection may use the Schema to prepare ds@1952: ** statements. ds@1952: */ ds@1952: struct Schema { ds@1952: int schema_cookie; /* Database schema version number for this file */ ds@1952: Hash tblHash; /* All tables indexed by name */ ds@1952: Hash idxHash; /* All (named) indices indexed by name */ ds@1952: Hash trigHash; /* All triggers indexed by name */ ds@1952: Hash aFKey; /* Foreign keys indexed by to-table */ ds@1952: Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */ ds@1952: u8 file_format; /* Schema format version for this file */ ds@1952: u8 enc; /* Text encoding used by this database */ ds@1952: u16 flags; /* Flags associated with this schema */ ds@1952: int cache_size; /* Number of pages to use in the cache */ ds@1952: #ifndef SQLITE_OMIT_VIRTUALTABLE ds@1952: sqlite3 *db; /* "Owner" connection. See comment above */ ds@1952: #endif ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** These macros can be used to test, set, or clear bits in the ds@1952: ** Db.flags field. ds@1952: */ ds@1952: #define DbHasProperty(D,I,P) (((D)->aDb[I].pSchema->flags&(P))==(P)) ds@1952: #define DbHasAnyProperty(D,I,P) (((D)->aDb[I].pSchema->flags&(P))!=0) ds@1952: #define DbSetProperty(D,I,P) (D)->aDb[I].pSchema->flags|=(P) ds@1952: #define DbClearProperty(D,I,P) (D)->aDb[I].pSchema->flags&=~(P) ds@1952: ds@1952: /* ds@1952: ** Allowed values for the DB.flags field. ds@1952: ** ds@1952: ** The DB_SchemaLoaded flag is set after the database schema has been ds@1952: ** read into internal hash tables. ds@1952: ** ds@1952: ** DB_UnresetViews means that one or more views have column names that ds@1952: ** have been filled out. If the schema changes, these column names might ds@1952: ** changes and so the view will need to be reset. ds@1952: */ ds@1952: #define DB_SchemaLoaded 0x0001 /* The schema has been loaded */ ds@1952: #define DB_UnresetViews 0x0002 /* Some views have defined column names */ ds@1952: #define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */ ds@1952: ds@1952: ds@1952: /* ds@1952: ** Each database is an instance of the following structure. ds@1952: ** ds@1952: ** The sqlite.lastRowid records the last insert rowid generated by an ds@1952: ** insert statement. Inserts on views do not affect its value. Each ds@1952: ** trigger has its own context, so that lastRowid can be updated inside ds@1952: ** triggers as usual. The previous value will be restored once the trigger ds@1952: ** exits. Upon entering a before or instead of trigger, lastRowid is no ds@1952: ** longer (since after version 2.8.12) reset to -1. ds@1952: ** ds@1952: ** The sqlite.nChange does not count changes within triggers and keeps no ds@1952: ** context. It is reset at start of sqlite3_exec. ds@1952: ** The sqlite.lsChange represents the number of changes made by the last ds@1952: ** insert, update, or delete statement. It remains constant throughout the ds@1952: ** length of a statement and is then updated by OP_SetCounts. It keeps a ds@1952: ** context stack just like lastRowid so that the count of changes ds@1952: ** within a trigger is not seen outside the trigger. Changes to views do not ds@1952: ** affect the value of lsChange. ds@1952: ** The sqlite.csChange keeps track of the number of current changes (since ds@1952: ** the last statement) and is used to update sqlite_lsChange. ds@1952: ** ds@1952: ** The member variables sqlite.errCode, sqlite.zErrMsg and sqlite.zErrMsg16 ds@1952: ** store the most recent error code and, if applicable, string. The ds@1952: ** internal function sqlite3Error() is used to set these variables ds@1952: ** consistently. ds@1952: */ ds@1952: struct sqlite3 { ds@1952: sqlite3_vfs *pVfs; /* OS Interface */ ds@1952: int nDb; /* Number of backends currently in use */ ds@1952: Db *aDb; /* All backends */ ds@1952: int flags; /* Miscellanous flags. See below */ ds@1952: int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ ds@1952: int errCode; /* Most recent error code (SQLITE_*) */ ds@1952: int errMask; /* & result codes with this before returning */ ds@1952: u8 autoCommit; /* The auto-commit flag. */ ds@1952: u8 temp_store; /* 1: file 2: memory 0: default */ ds@1952: u8 mallocFailed; /* True if we have seen a malloc failure */ ds@1952: int nTable; /* Number of tables in the database */ ds@1952: CollSeq *pDfltColl; /* The default collating sequence (BINARY) */ ds@1952: i64 lastRowid; /* ROWID of most recent insert (see above) */ ds@1952: i64 priorNewRowid; /* Last randomly generated ROWID */ ds@1952: int magic; /* Magic number for detect library misuse */ ds@1952: int nChange; /* Value returned by sqlite3_changes() */ ds@1952: int nTotalChange; /* Value returned by sqlite3_total_changes() */ ds@1952: sqlite3_mutex *mutex; /* Connection mutex */ ds@1952: struct sqlite3InitInfo { /* Information used during initialization */ ds@1952: int iDb; /* When back is being initialized */ ds@1952: int newTnum; /* Rootpage of table being initialized */ ds@1952: u8 busy; /* TRUE if currently initializing */ ds@1952: } init; ds@1952: int nExtension; /* Number of loaded extensions */ ds@1952: void **aExtension; /* Array of shared libraray handles */ ds@1952: struct Vdbe *pVdbe; /* List of active virtual machines */ ds@1952: int activeVdbeCnt; /* Number of vdbes currently executing */ ds@1952: void (*xTrace)(void*,const char*); /* Trace function */ ds@1952: void *pTraceArg; /* Argument to the trace function */ ds@1952: void (*xProfile)(void*,const char*,u64); /* Profiling function */ ds@1952: void *pProfileArg; /* Argument to profile function */ ds@1952: void *pCommitArg; /* Argument to xCommitCallback() */ ds@1952: int (*xCommitCallback)(void*); /* Invoked at every commit. */ ds@1952: void *pRollbackArg; /* Argument to xRollbackCallback() */ ds@1952: void (*xRollbackCallback)(void*); /* Invoked at every commit. */ ds@1952: void *pUpdateArg; ds@1952: void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64); ds@1952: void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*); ds@1952: void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*); ds@1952: void *pCollNeededArg; ds@1952: sqlite3_value *pErr; /* Most recent error message */ ds@1952: char *zErrMsg; /* Most recent error message (UTF-8 encoded) */ ds@1952: char *zErrMsg16; /* Most recent error message (UTF-16 encoded) */ ds@1952: union { ds@1952: int isInterrupted; /* True if sqlite3_interrupt has been called */ ds@1952: double notUsed1; /* Spacer */ ds@1952: } u1; ds@1952: #ifndef SQLITE_OMIT_AUTHORIZATION ds@1952: int (*xAuth)(void*,int,const char*,const char*,const char*,const char*); ds@1952: /* Access authorization function */ ds@1952: void *pAuthArg; /* 1st argument to the access auth function */ ds@1952: #endif ds@1952: #ifndef SQLITE_OMIT_PROGRESS_CALLBACK ds@1952: int (*xProgress)(void *); /* The progress callback */ ds@1952: void *pProgressArg; /* Argument to the progress callback */ ds@1952: int nProgressOps; /* Number of opcodes for progress callback */ ds@1952: #endif ds@1952: #ifndef SQLITE_OMIT_VIRTUALTABLE ds@1952: Hash aModule; /* populated by sqlite3_create_module() */ ds@1952: Table *pVTab; /* vtab with active Connect/Create method */ ds@1952: sqlite3_vtab **aVTrans; /* Virtual tables with open transactions */ ds@1952: int nVTrans; /* Allocated size of aVTrans */ ds@1952: #endif ds@1952: Hash aFunc; /* All functions that can be in SQL exprs */ ds@1952: Hash aCollSeq; /* All collating sequences */ ds@1952: BusyHandler busyHandler; /* Busy callback */ ds@1952: int busyTimeout; /* Busy handler timeout, in msec */ ds@1952: Db aDbStatic[2]; /* Static space for the 2 default backends */ ds@1952: #ifdef SQLITE_SSE ds@1952: sqlite3_stmt *pFetch; /* Used by SSE to fetch stored statements */ ds@1952: #endif ds@1952: u8 dfltLockMode; /* Default locking-mode for attached dbs */ ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** A macro to discover the encoding of a database. ds@1952: */ ds@1952: #define ENC(db) ((db)->aDb[0].pSchema->enc) ds@1952: ds@1952: /* ds@1952: ** Possible values for the sqlite.flags and or Db.flags fields. ds@1952: ** ds@1952: ** On sqlite.flags, the SQLITE_InTrans value means that we have ds@1952: ** executed a BEGIN. On Db.flags, SQLITE_InTrans means a statement ds@1952: ** transaction is active on that particular database file. ds@1952: */ ds@1952: #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */ ds@1952: #define SQLITE_InTrans 0x00000008 /* True if in a transaction */ ds@1952: #define SQLITE_InternChanges 0x00000010 /* Uncommitted Hash table changes */ ds@1952: #define SQLITE_FullColNames 0x00000020 /* Show full column names on SELECT */ ds@1952: #define SQLITE_ShortColNames 0x00000040 /* Show short columns names */ ds@1952: #define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */ ds@1952: /* DELETE, or UPDATE and return */ ds@1952: /* the count using a callback. */ ds@1952: #define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */ ds@1952: /* result set is empty */ ds@1952: #define SQLITE_SqlTrace 0x00000200 /* Debug print SQL as it executes */ ds@1952: #define SQLITE_VdbeListing 0x00000400 /* Debug listings of VDBE programs */ ds@1952: #define SQLITE_WriteSchema 0x00000800 /* OK to update SQLITE_MASTER */ ds@1952: #define SQLITE_NoReadlock 0x00001000 /* Readlocks are omitted when ds@1952: ** accessing read-only databases */ ds@1952: #define SQLITE_IgnoreChecks 0x00002000 /* Do not enforce check constraints */ ds@1952: #define SQLITE_ReadUncommitted 0x00004000 /* For shared-cache mode */ ds@1952: #define SQLITE_LegacyFileFmt 0x00008000 /* Create new databases in format 1 */ ds@1952: #define SQLITE_FullFSync 0x00010000 /* Use full fsync on the backend */ ds@1952: #define SQLITE_LoadExtension 0x00020000 /* Enable load_extension */ ds@1952: ds@1952: #define SQLITE_RecoveryMode 0x00040000 /* Ignore schema errors */ ds@1952: #define SQLITE_SharedCache 0x00080000 /* Cache sharing is enabled */ ds@1952: #define SQLITE_Vtab 0x00100000 /* There exists a virtual table */ ds@1952: ds@1952: /* ds@1952: ** Possible values for the sqlite.magic field. ds@1952: ** The numbers are obtained at random and have no special meaning, other ds@1952: ** than being distinct from one another. ds@1952: */ ds@1952: #define SQLITE_MAGIC_OPEN 0xa029a697 /* Database is open */ ds@1952: #define SQLITE_MAGIC_CLOSED 0x9f3c2d33 /* Database is closed */ ds@1952: #define SQLITE_MAGIC_BUSY 0xf03b7906 /* Database currently in use */ ds@1952: #define SQLITE_MAGIC_ERROR 0xb5357930 /* An SQLITE_MISUSE error occurred */ ds@1952: ds@1952: /* ds@1952: ** Each SQL function is defined by an instance of the following ds@1952: ** structure. A pointer to this structure is stored in the sqlite.aFunc ds@1952: ** hash table. When multiple functions have the same name, the hash table ds@1952: ** points to a linked list of these structures. ds@1952: */ ds@1952: struct FuncDef { ds@1952: i16 nArg; /* Number of arguments. -1 means unlimited */ ds@1952: u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */ ds@1952: u8 needCollSeq; /* True if sqlite3GetFuncCollSeq() might be called */ ds@1952: u8 flags; /* Some combination of SQLITE_FUNC_* */ ds@1952: void *pUserData; /* User data parameter */ ds@1952: FuncDef *pNext; /* Next function with same name */ ds@1952: void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */ ds@1952: void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */ ds@1952: void (*xFinalize)(sqlite3_context*); /* Aggregate finializer */ ds@1952: char zName[1]; /* SQL name of the function. MUST BE LAST */ ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** Each SQLite module (virtual table definition) is defined by an ds@1952: ** instance of the following structure, stored in the sqlite3.aModule ds@1952: ** hash table. ds@1952: */ ds@1952: struct Module { ds@1952: const sqlite3_module *pModule; /* Callback pointers */ ds@1952: const char *zName; /* Name passed to create_module() */ ds@1952: void *pAux; /* pAux passed to create_module() */ ds@1952: void (*xDestroy)(void *); /* Module destructor function */ ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** Possible values for FuncDef.flags ds@1952: */ ds@1952: #define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */ ds@1952: #define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */ ds@1952: #define SQLITE_FUNC_EPHEM 0x04 /* Ephermeral. Delete with VDBE */ ds@1952: ds@1952: /* ds@1952: ** information about each column of an SQL table is held in an instance ds@1952: ** of this structure. ds@1952: */ ds@1952: struct Column { ds@1952: char *zName; /* Name of this column */ ds@1952: Expr *pDflt; /* Default value of this column */ ds@1952: char *zType; /* Data type for this column */ ds@1952: char *zColl; /* Collating sequence. If NULL, use the default */ ds@1952: u8 notNull; /* True if there is a NOT NULL constraint */ ds@1952: u8 isPrimKey; /* True if this column is part of the PRIMARY KEY */ ds@1952: char affinity; /* One of the SQLITE_AFF_... values */ ds@1952: #ifndef SQLITE_OMIT_VIRTUALTABLE ds@1952: u8 isHidden; /* True if this column is 'hidden' */ ds@1952: #endif ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** A "Collating Sequence" is defined by an instance of the following ds@1952: ** structure. Conceptually, a collating sequence consists of a name and ds@1952: ** a comparison routine that defines the order of that sequence. ds@1952: ** ds@1952: ** There may two seperate implementations of the collation function, one ds@1952: ** that processes text in UTF-8 encoding (CollSeq.xCmp) and another that ds@1952: ** processes text encoded in UTF-16 (CollSeq.xCmp16), using the machine ds@1952: ** native byte order. When a collation sequence is invoked, SQLite selects ds@1952: ** the version that will require the least expensive encoding ds@1952: ** translations, if any. ds@1952: ** ds@1952: ** The CollSeq.pUser member variable is an extra parameter that passed in ds@1952: ** as the first argument to the UTF-8 comparison function, xCmp. ds@1952: ** CollSeq.pUser16 is the equivalent for the UTF-16 comparison function, ds@1952: ** xCmp16. ds@1952: ** ds@1952: ** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the ds@1952: ** collating sequence is undefined. Indices built on an undefined ds@1952: ** collating sequence may not be read or written. ds@1952: */ ds@1952: struct CollSeq { ds@1952: char *zName; /* Name of the collating sequence, UTF-8 encoded */ ds@1952: u8 enc; /* Text encoding handled by xCmp() */ ds@1952: u8 type; /* One of the SQLITE_COLL_... values below */ ds@1952: void *pUser; /* First argument to xCmp() */ ds@1952: int (*xCmp)(void*,int, const void*, int, const void*); ds@1952: void (*xDel)(void*); /* Destructor for pUser */ ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** Allowed values of CollSeq flags: ds@1952: */ ds@1952: #define SQLITE_COLL_BINARY 1 /* The default memcmp() collating sequence */ ds@1952: #define SQLITE_COLL_NOCASE 2 /* The built-in NOCASE collating sequence */ ds@1952: #define SQLITE_COLL_REVERSE 3 /* The built-in REVERSE collating sequence */ ds@1952: #define SQLITE_COLL_USER 0 /* Any other user-defined collating sequence */ ds@1952: ds@1952: /* ds@1952: ** A sort order can be either ASC or DESC. ds@1952: */ ds@1952: #define SQLITE_SO_ASC 0 /* Sort in ascending order */ ds@1952: #define SQLITE_SO_DESC 1 /* Sort in ascending order */ ds@1952: ds@1952: /* ds@1952: ** Column affinity types. ds@1952: ** ds@1952: ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and ds@1952: ** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve ds@1952: ** the speed a little by number the values consecutively. ds@1952: ** ds@1952: ** But rather than start with 0 or 1, we begin with 'a'. That way, ds@1952: ** when multiple affinity types are concatenated into a string and ds@1952: ** used as the P3 operand, they will be more readable. ds@1952: ** ds@1952: ** Note also that the numeric types are grouped together so that testing ds@1952: ** for a numeric type is a single comparison. ds@1952: */ ds@1952: #define SQLITE_AFF_TEXT 'a' ds@1952: #define SQLITE_AFF_NONE 'b' ds@1952: #define SQLITE_AFF_NUMERIC 'c' ds@1952: #define SQLITE_AFF_INTEGER 'd' ds@1952: #define SQLITE_AFF_REAL 'e' ds@1952: ds@1952: #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC) ds@1952: ds@1952: /* ds@1952: ** Each SQL table is represented in memory by an instance of the ds@1952: ** following structure. ds@1952: ** ds@1952: ** Table.zName is the name of the table. The case of the original ds@1952: ** CREATE TABLE statement is stored, but case is not significant for ds@1952: ** comparisons. ds@1952: ** ds@1952: ** Table.nCol is the number of columns in this table. Table.aCol is a ds@1952: ** pointer to an array of Column structures, one for each column. ds@1952: ** ds@1952: ** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of ds@1952: ** the column that is that key. Otherwise Table.iPKey is negative. Note ds@1952: ** that the datatype of the PRIMARY KEY must be INTEGER for this field to ds@1952: ** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of ds@1952: ** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid ds@1952: ** is generated for each row of the table. Table.hasPrimKey is true if ds@1952: ** the table has any PRIMARY KEY, INTEGER or otherwise. ds@1952: ** ds@1952: ** Table.tnum is the page number for the root BTree page of the table in the ds@1952: ** database file. If Table.iDb is the index of the database table backend ds@1952: ** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that ds@1952: ** holds temporary tables and indices. If Table.isEphem ds@1952: ** is true, then the table is stored in a file that is automatically deleted ds@1952: ** when the VDBE cursor to the table is closed. In this case Table.tnum ds@1952: ** refers VDBE cursor number that holds the table open, not to the root ds@1952: ** page number. Transient tables are used to hold the results of a ds@1952: ** sub-query that appears instead of a real table name in the FROM clause ds@1952: ** of a SELECT statement. ds@1952: */ ds@1952: struct Table { ds@1952: char *zName; /* Name of the table */ ds@1952: int nCol; /* Number of columns in this table */ ds@1952: Column *aCol; /* Information about each column */ ds@1952: int iPKey; /* If not less then 0, use aCol[iPKey] as the primary key */ ds@1952: Index *pIndex; /* List of SQL indexes on this table. */ ds@1952: int tnum; /* Root BTree node for this table (see note above) */ ds@1952: Select *pSelect; /* NULL for tables. Points to definition if a view. */ ds@1952: int nRef; /* Number of pointers to this Table */ ds@1952: Trigger *pTrigger; /* List of SQL triggers on this table */ ds@1952: FKey *pFKey; /* Linked list of all foreign keys in this table */ ds@1952: char *zColAff; /* String defining the affinity of each column */ ds@1952: #ifndef SQLITE_OMIT_CHECK ds@1952: Expr *pCheck; /* The AND of all CHECK constraints */ ds@1952: #endif ds@1952: #ifndef SQLITE_OMIT_ALTERTABLE ds@1952: int addColOffset; /* Offset in CREATE TABLE statement to add a new column */ ds@1952: #endif ds@1952: u8 readOnly; /* True if this table should not be written by the user */ ds@1952: u8 isEphem; /* True if created using OP_OpenEphermeral */ ds@1952: u8 hasPrimKey; /* True if there exists a primary key */ ds@1952: u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ ds@1952: u8 autoInc; /* True if the integer primary key is autoincrement */ ds@1952: #ifndef SQLITE_OMIT_VIRTUALTABLE ds@1952: u8 isVirtual; /* True if this is a virtual table */ ds@1952: u8 isCommit; /* True once the CREATE TABLE has been committed */ ds@1952: Module *pMod; /* Pointer to the implementation of the module */ ds@1952: sqlite3_vtab *pVtab; /* Pointer to the module instance */ ds@1952: int nModuleArg; /* Number of arguments to the module */ ds@1952: char **azModuleArg; /* Text of all module args. [0] is module name */ ds@1952: #endif ds@1952: Schema *pSchema; /* Schema that contains this table */ ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** Test to see whether or not a table is a virtual table. This is ds@1952: ** done as a macro so that it will be optimized out when virtual ds@1952: ** table support is omitted from the build. ds@1952: */ ds@1952: #ifndef SQLITE_OMIT_VIRTUALTABLE ds@1952: # define IsVirtual(X) ((X)->isVirtual) ds@1952: # define IsHiddenColumn(X) ((X)->isHidden) ds@1952: #else ds@1952: # define IsVirtual(X) 0 ds@1952: # define IsHiddenColumn(X) 0 ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** Each foreign key constraint is an instance of the following structure. ds@1952: ** ds@1952: ** A foreign key is associated with two tables. The "from" table is ds@1952: ** the table that contains the REFERENCES clause that creates the foreign ds@1952: ** key. The "to" table is the table that is named in the REFERENCES clause. ds@1952: ** Consider this example: ds@1952: ** ds@1952: ** CREATE TABLE ex1( ds@1952: ** a INTEGER PRIMARY KEY, ds@1952: ** b INTEGER CONSTRAINT fk1 REFERENCES ex2(x) ds@1952: ** ); ds@1952: ** ds@1952: ** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2". ds@1952: ** ds@1952: ** Each REFERENCES clause generates an instance of the following structure ds@1952: ** which is attached to the from-table. The to-table need not exist when ds@1952: ** the from-table is created. The existance of the to-table is not checked ds@1952: ** until an attempt is made to insert data into the from-table. ds@1952: ** ds@1952: ** The sqlite.aFKey hash table stores pointers to this structure ds@1952: ** given the name of a to-table. For each to-table, all foreign keys ds@1952: ** associated with that table are on a linked list using the FKey.pNextTo ds@1952: ** field. ds@1952: */ ds@1952: struct FKey { ds@1952: Table *pFrom; /* The table that constains the REFERENCES clause */ ds@1952: FKey *pNextFrom; /* Next foreign key in pFrom */ ds@1952: char *zTo; /* Name of table that the key points to */ ds@1952: FKey *pNextTo; /* Next foreign key that points to zTo */ ds@1952: int nCol; /* Number of columns in this key */ ds@1952: struct sColMap { /* Mapping of columns in pFrom to columns in zTo */ ds@1952: int iFrom; /* Index of column in pFrom */ ds@1952: char *zCol; /* Name of column in zTo. If 0 use PRIMARY KEY */ ds@1952: } *aCol; /* One entry for each of nCol column s */ ds@1952: u8 isDeferred; /* True if constraint checking is deferred till COMMIT */ ds@1952: u8 updateConf; /* How to resolve conflicts that occur on UPDATE */ ds@1952: u8 deleteConf; /* How to resolve conflicts that occur on DELETE */ ds@1952: u8 insertConf; /* How to resolve conflicts that occur on INSERT */ ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** SQLite supports many different ways to resolve a constraint ds@1952: ** error. ROLLBACK processing means that a constraint violation ds@1952: ** causes the operation in process to fail and for the current transaction ds@1952: ** to be rolled back. ABORT processing means the operation in process ds@1952: ** fails and any prior changes from that one operation are backed out, ds@1952: ** but the transaction is not rolled back. FAIL processing means that ds@1952: ** the operation in progress stops and returns an error code. But prior ds@1952: ** changes due to the same operation are not backed out and no rollback ds@1952: ** occurs. IGNORE means that the particular row that caused the constraint ds@1952: ** error is not inserted or updated. Processing continues and no error ds@1952: ** is returned. REPLACE means that preexisting database rows that caused ds@1952: ** a UNIQUE constraint violation are removed so that the new insert or ds@1952: ** update can proceed. Processing continues and no error is reported. ds@1952: ** ds@1952: ** RESTRICT, SETNULL, and CASCADE actions apply only to foreign keys. ds@1952: ** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the ds@1952: ** same as ROLLBACK for DEFERRED keys. SETNULL means that the foreign ds@1952: ** key is set to NULL. CASCADE means that a DELETE or UPDATE of the ds@1952: ** referenced table row is propagated into the row that holds the ds@1952: ** foreign key. ds@1952: ** ds@1952: ** The following symbolic values are used to record which type ds@1952: ** of action to take. ds@1952: */ ds@1952: #define OE_None 0 /* There is no constraint to check */ ds@1952: #define OE_Rollback 1 /* Fail the operation and rollback the transaction */ ds@1952: #define OE_Abort 2 /* Back out changes but do no rollback transaction */ ds@1952: #define OE_Fail 3 /* Stop the operation but leave all prior changes */ ds@1952: #define OE_Ignore 4 /* Ignore the error. Do not do the INSERT or UPDATE */ ds@1952: #define OE_Replace 5 /* Delete existing record, then do INSERT or UPDATE */ ds@1952: ds@1952: #define OE_Restrict 6 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */ ds@1952: #define OE_SetNull 7 /* Set the foreign key value to NULL */ ds@1952: #define OE_SetDflt 8 /* Set the foreign key value to its default */ ds@1952: #define OE_Cascade 9 /* Cascade the changes */ ds@1952: ds@1952: #define OE_Default 99 /* Do whatever the default action is */ ds@1952: ds@1952: ds@1952: /* ds@1952: ** An instance of the following structure is passed as the first ds@1952: ** argument to sqlite3VdbeKeyCompare and is used to control the ds@1952: ** comparison of the two index keys. ds@1952: ** ds@1952: ** If the KeyInfo.incrKey value is true and the comparison would ds@1952: ** otherwise be equal, then return a result as if the second key ds@1952: ** were larger. ds@1952: */ ds@1952: struct KeyInfo { ds@1952: sqlite3 *db; /* The database connection */ ds@1952: u8 enc; /* Text encoding - one of the TEXT_Utf* values */ ds@1952: u8 incrKey; /* Increase 2nd key by epsilon before comparison */ ds@1952: int nField; /* Number of entries in aColl[] */ ds@1952: u8 *aSortOrder; /* If defined an aSortOrder[i] is true, sort DESC */ ds@1952: CollSeq *aColl[1]; /* Collating sequence for each term of the key */ ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** Each SQL index is represented in memory by an ds@1952: ** instance of the following structure. ds@1952: ** ds@1952: ** The columns of the table that are to be indexed are described ds@1952: ** by the aiColumn[] field of this structure. For example, suppose ds@1952: ** we have the following table and index: ds@1952: ** ds@1952: ** CREATE TABLE Ex1(c1 int, c2 int, c3 text); ds@1952: ** CREATE INDEX Ex2 ON Ex1(c3,c1); ds@1952: ** ds@1952: ** In the Table structure describing Ex1, nCol==3 because there are ds@1952: ** three columns in the table. In the Index structure describing ds@1952: ** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed. ds@1952: ** The value of aiColumn is {2, 0}. aiColumn[0]==2 because the ds@1952: ** first column to be indexed (c3) has an index of 2 in Ex1.aCol[]. ds@1952: ** The second column to be indexed (c1) has an index of 0 in ds@1952: ** Ex1.aCol[], hence Ex2.aiColumn[1]==0. ds@1952: ** ds@1952: ** The Index.onError field determines whether or not the indexed columns ds@1952: ** must be unique and what to do if they are not. When Index.onError=OE_None, ds@1952: ** it means this is not a unique index. Otherwise it is a unique index ds@1952: ** and the value of Index.onError indicate the which conflict resolution ds@1952: ** algorithm to employ whenever an attempt is made to insert a non-unique ds@1952: ** element. ds@1952: */ ds@1952: struct Index { ds@1952: char *zName; /* Name of this index */ ds@1952: int nColumn; /* Number of columns in the table used by this index */ ds@1952: int *aiColumn; /* Which columns are used by this index. 1st is 0 */ ds@1952: unsigned *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */ ds@1952: Table *pTable; /* The SQL table being indexed */ ds@1952: int tnum; /* Page containing root of this index in database file */ ds@1952: u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ ds@1952: u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */ ds@1952: char *zColAff; /* String defining the affinity of each column */ ds@1952: Index *pNext; /* The next index associated with the same table */ ds@1952: Schema *pSchema; /* Schema containing this index */ ds@1952: u8 *aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */ ds@1952: char **azColl; /* Array of collation sequence names for index */ ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** Each token coming out of the lexer is an instance of ds@1952: ** this structure. Tokens are also used as part of an expression. ds@1952: ** ds@1952: ** Note if Token.z==0 then Token.dyn and Token.n are undefined and ds@1952: ** may contain random values. Do not make any assuptions about Token.dyn ds@1952: ** and Token.n when Token.z==0. ds@1952: */ ds@1952: struct Token { ds@1952: const unsigned char *z; /* Text of the token. Not NULL-terminated! */ ds@1952: unsigned dyn : 1; /* True for malloced memory, false for static */ ds@1952: unsigned n : 31; /* Number of characters in this token */ ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** An instance of this structure contains information needed to generate ds@1952: ** code for a SELECT that contains aggregate functions. ds@1952: ** ds@1952: ** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a ds@1952: ** pointer to this structure. The Expr.iColumn field is the index in ds@1952: ** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate ds@1952: ** code for that node. ds@1952: ** ds@1952: ** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the ds@1952: ** original Select structure that describes the SELECT statement. These ds@1952: ** fields do not need to be freed when deallocating the AggInfo structure. ds@1952: */ ds@1952: struct AggInfo { ds@1952: u8 directMode; /* Direct rendering mode means take data directly ds@1952: ** from source tables rather than from accumulators */ ds@1952: u8 useSortingIdx; /* In direct mode, reference the sorting index rather ds@1952: ** than the source table */ ds@1952: int sortingIdx; /* Cursor number of the sorting index */ ds@1952: ExprList *pGroupBy; /* The group by clause */ ds@1952: int nSortingColumn; /* Number of columns in the sorting index */ ds@1952: struct AggInfo_col { /* For each column used in source tables */ ds@1952: Table *pTab; /* Source table */ ds@1952: int iTable; /* Cursor number of the source table */ ds@1952: int iColumn; /* Column number within the source table */ ds@1952: int iSorterColumn; /* Column number in the sorting index */ ds@1952: int iMem; /* Memory location that acts as accumulator */ ds@1952: Expr *pExpr; /* The original expression */ ds@1952: } *aCol; ds@1952: int nColumn; /* Number of used entries in aCol[] */ ds@1952: int nColumnAlloc; /* Number of slots allocated for aCol[] */ ds@1952: int nAccumulator; /* Number of columns that show through to the output. ds@1952: ** Additional columns are used only as parameters to ds@1952: ** aggregate functions */ ds@1952: struct AggInfo_func { /* For each aggregate function */ ds@1952: Expr *pExpr; /* Expression encoding the function */ ds@1952: FuncDef *pFunc; /* The aggregate function implementation */ ds@1952: int iMem; /* Memory location that acts as accumulator */ ds@1952: int iDistinct; /* Ephermeral table used to enforce DISTINCT */ ds@1952: } *aFunc; ds@1952: int nFunc; /* Number of entries in aFunc[] */ ds@1952: int nFuncAlloc; /* Number of slots allocated for aFunc[] */ ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** Each node of an expression in the parse tree is an instance ds@1952: ** of this structure. ds@1952: ** ds@1952: ** Expr.op is the opcode. The integer parser token codes are reused ds@1952: ** as opcodes here. For example, the parser defines TK_GE to be an integer ds@1952: ** code representing the ">=" operator. This same integer code is reused ds@1952: ** to represent the greater-than-or-equal-to operator in the expression ds@1952: ** tree. ds@1952: ** ds@1952: ** Expr.pRight and Expr.pLeft are subexpressions. Expr.pList is a list ds@1952: ** of argument if the expression is a function. ds@1952: ** ds@1952: ** Expr.token is the operator token for this node. For some expressions ds@1952: ** that have subexpressions, Expr.token can be the complete text that gave ds@1952: ** rise to the Expr. In the latter case, the token is marked as being ds@1952: ** a compound token. ds@1952: ** ds@1952: ** An expression of the form ID or ID.ID refers to a column in a table. ds@1952: ** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is ds@1952: ** the integer cursor number of a VDBE cursor pointing to that table and ds@1952: ** Expr.iColumn is the column number for the specific column. If the ds@1952: ** expression is used as a result in an aggregate SELECT, then the ds@1952: ** value is also stored in the Expr.iAgg column in the aggregate so that ds@1952: ** it can be accessed after all aggregates are computed. ds@1952: ** ds@1952: ** If the expression is a function, the Expr.iTable is an integer code ds@1952: ** representing which function. If the expression is an unbound variable ds@1952: ** marker (a question mark character '?' in the original SQL) then the ds@1952: ** Expr.iTable holds the index number for that variable. ds@1952: ** ds@1952: ** If the expression is a subquery then Expr.iColumn holds an integer ds@1952: ** register number containing the result of the subquery. If the ds@1952: ** subquery gives a constant result, then iTable is -1. If the subquery ds@1952: ** gives a different answer at different times during statement processing ds@1952: ** then iTable is the address of a subroutine that computes the subquery. ds@1952: ** ds@1952: ** The Expr.pSelect field points to a SELECT statement. The SELECT might ds@1952: ** be the right operand of an IN operator. Or, if a scalar SELECT appears ds@1952: ** in an expression the opcode is TK_SELECT and Expr.pSelect is the only ds@1952: ** operand. ds@1952: ** ds@1952: ** If the Expr is of type OP_Column, and the table it is selecting from ds@1952: ** is a disk table or the "old.*" pseudo-table, then pTab points to the ds@1952: ** corresponding table definition. ds@1952: */ ds@1952: struct Expr { ds@1952: u8 op; /* Operation performed by this node */ ds@1952: char affinity; /* The affinity of the column or 0 if not a column */ ds@1952: u16 flags; /* Various flags. See below */ ds@1952: CollSeq *pColl; /* The collation type of the column or 0 */ ds@1952: Expr *pLeft, *pRight; /* Left and right subnodes */ ds@1952: ExprList *pList; /* A list of expressions used as function arguments ds@1952: ** or in " IN (aCol[] or ->aFunc[] */ ds@1952: int iRightJoinTable; /* If EP_FromJoin, the right table of the join */ ds@1952: Select *pSelect; /* When the expression is a sub-select. Also the ds@1952: ** right side of " IN (