📄 sqliteint.h
字号:
/*** Forward references to structures*/typedef struct Column Column;typedef struct Table Table;typedef struct Index Index;typedef struct Expr Expr;typedef struct ExprList ExprList;typedef struct Parse Parse;typedef struct Token Token;typedef struct IdList IdList;typedef struct SrcList SrcList;typedef struct WhereInfo WhereInfo;typedef struct WhereLevel WhereLevel;typedef struct Select Select;typedef struct AggExpr AggExpr;typedef struct FuncDef FuncDef;typedef struct Trigger Trigger;typedef struct TriggerStep TriggerStep;typedef struct TriggerStack TriggerStack;typedef struct FKey FKey;typedef struct Db Db;typedef struct AuthContext AuthContext;typedef struct KeyClass KeyClass;typedef struct CollSeq CollSeq;typedef struct KeyInfo KeyInfo;typedef struct NameContext NameContext;/*** Each database file to be accessed by the system is an instance** of the following structure. There are normally two of these structures** in the sqlite.aDb[] array. aDb[0] is the main database file and** aDb[1] is the database file used to hold temporary tables. Additional** databases may be attached.*/struct Db { char *zName; /* Name of this database */ Btree *pBt; /* The B*Tree structure for this database file */ int schema_cookie; /* Database schema version number for this file */ Hash tblHash; /* All tables indexed by name */ Hash idxHash; /* All (named) indices indexed by name */ Hash trigHash; /* All triggers indexed by name */ Hash aFKey; /* Foreign keys indexed by to-table */ u16 flags; /* Flags associated with this database */ u8 inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */ u8 safety_level; /* How aggressive at synching data to disk */ int cache_size; /* Number of pages to use in the cache */ Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */ void *pAux; /* Auxiliary data. Usually NULL */ void (*xFreeAux)(void*); /* Routine to free pAux */};/*** These macros can be used to test, set, or clear bits in the ** Db.flags field.*/#define DbHasProperty(D,I,P) (((D)->aDb[I].flags&(P))==(P))#define DbHasAnyProperty(D,I,P) (((D)->aDb[I].flags&(P))!=0)#define DbSetProperty(D,I,P) (D)->aDb[I].flags|=(P)#define DbClearProperty(D,I,P) (D)->aDb[I].flags&=~(P)/*** Allowed values for the DB.flags field.**** The DB_SchemaLoaded flag is set after the database schema has been** read into internal hash tables.**** DB_UnresetViews means that one or more views have column names that** have been filled out. If the schema changes, these column names might** changes and so the view will need to be reset.*/#define DB_SchemaLoaded 0x0001 /* The schema has been loaded */#define DB_UnresetViews 0x0002 /* Some views have defined column names */#define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)/*** Each database is an instance of the following structure.**** The sqlite.lastRowid records the last insert rowid generated by an** insert statement. Inserts on views do not affect its value. Each** trigger has its own context, so that lastRowid can be updated inside** triggers as usual. The previous value will be restored once the trigger** exits. Upon entering a before or instead of trigger, lastRowid is no** longer (since after version 2.8.12) reset to -1.**** The sqlite.nChange does not count changes within triggers and keeps no** context. It is reset at start of sqlite3_exec.** The sqlite.lsChange represents the number of changes made by the last** insert, update, or delete statement. It remains constant throughout the** length of a statement and is then updated by OP_SetCounts. It keeps a** context stack just like lastRowid so that the count of changes** within a trigger is not seen outside the trigger. Changes to views do not** affect the value of lsChange.** The sqlite.csChange keeps track of the number of current changes (since** the last statement) and is used to update sqlite_lsChange.**** The member variables sqlite.errCode, sqlite.zErrMsg and sqlite.zErrMsg16** store the most recent error code and, if applicable, string. The** internal function sqlite3Error() is used to set these variables** consistently.*/struct sqlite3 { int nDb; /* Number of backends currently in use */ Db *aDb; /* All backends */ int flags; /* Miscellanous flags. See below */ int errCode; /* Most recent error code (SQLITE_*) */ u8 enc; /* Text encoding for this database. */ u8 autoCommit; /* The auto-commit flag. */ u8 file_format; /* What file format version is this database? */ u8 temp_store; /* 1: file 2: memory 0: default */ int nTable; /* Number of tables in the database */ CollSeq *pDfltColl; /* The default collating sequence (BINARY) */ i64 lastRowid; /* ROWID of most recent insert (see above) */ i64 priorNewRowid; /* Last randomly generated ROWID */ int magic; /* Magic number for detect library misuse */ int nChange; /* Value returned by sqlite3_changes() */ int nTotalChange; /* Value returned by sqlite3_total_changes() */ struct sqlite3InitInfo { /* Information used during initialization */ int iDb; /* When back is being initialized */ int newTnum; /* Rootpage of table being initialized */ u8 busy; /* TRUE if currently initializing */ } init; struct Vdbe *pVdbe; /* List of active virtual machines */ int activeVdbeCnt; /* Number of vdbes currently executing */ void (*xTrace)(void*,const char*); /* Trace function */ void *pTraceArg; /* Argument to the trace function */ void *pCommitArg; /* Argument to xCommitCallback() */ int (*xCommitCallback)(void*);/* Invoked at every commit. */ void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*); void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*); void *pCollNeededArg; sqlite3_value *pValue; /* Value used for transient conversions */ sqlite3_value *pErr; /* Most recent error message */ char *zErrMsg; /* Most recent error message (UTF-8 encoded) */ char *zErrMsg16; /* Most recent error message (UTF-16 encoded) */#ifndef SQLITE_OMIT_AUTHORIZATION int (*xAuth)(void*,int,const char*,const char*,const char*,const char*); /* Access authorization function */ void *pAuthArg; /* 1st argument to the access auth function */#endif#ifndef SQLITE_OMIT_PROGRESS_CALLBACK int (*xProgress)(void *); /* The progress callback */ void *pProgressArg; /* Argument to the progress callback */ int nProgressOps; /* Number of opcodes for progress callback */#endif#ifndef SQLITE_OMIT_GLOBALRECOVER sqlite3 *pNext; /* Linked list of open db handles. */#endif Hash aFunc; /* All functions that can be in SQL exprs */ Hash aCollSeq; /* All collating sequences */ BusyHandler busyHandler; /* Busy callback */ int busyTimeout; /* Busy handler timeout, in msec */ Db aDbStatic[2]; /* Static space for the 2 default backends */#ifdef SQLITE_SSE sqlite3_stmt *pFetch; /* Used by SSE to fetch stored statements */#endif};/*** Possible values for the sqlite.flags and or Db.flags fields.**** On sqlite.flags, the SQLITE_InTrans value means that we have** executed a BEGIN. On Db.flags, SQLITE_InTrans means a statement** transaction is active on that particular database file.*/#define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */#define SQLITE_Initialized 0x00000002 /* True after initialization */#define SQLITE_Interrupt 0x00000004 /* Cancel current operation */#define SQLITE_InTrans 0x00000008 /* True if in a transaction */#define SQLITE_InternChanges 0x00000010 /* Uncommitted Hash table changes */#define SQLITE_FullColNames 0x00000020 /* Show full column names on SELECT */#define SQLITE_ShortColNames 0x00000040 /* Show short columns names */#define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */ /* DELETE, or UPDATE and return */ /* the count using a callback. */#define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */ /* result set is empty */#define SQLITE_SqlTrace 0x00000200 /* Debug print SQL as it executes */#define SQLITE_VdbeListing 0x00000400 /* Debug listings of VDBE programs */#define SQLITE_WriteSchema 0x00000800 /* OK to update SQLITE_MASTER */#define SQLITE_NoReadlock 0x00001000 /* Readlocks are omitted when ** accessing read-only databases *//*** Possible values for the sqlite.magic field.** The numbers are obtained at random and have no special meaning, other** than being distinct from one another.*/#define SQLITE_MAGIC_OPEN 0xa029a697 /* Database is open */#define SQLITE_MAGIC_CLOSED 0x9f3c2d33 /* Database is closed */#define SQLITE_MAGIC_BUSY 0xf03b7906 /* Database currently in use */#define SQLITE_MAGIC_ERROR 0xb5357930 /* An SQLITE_MISUSE error occurred *//*** Each SQL function is defined by an instance of the following** structure. A pointer to this structure is stored in the sqlite.aFunc** hash table. When multiple functions have the same name, the hash table** points to a linked list of these structures.*/struct FuncDef { char *zName; /* SQL name of the function */ int nArg; /* Number of arguments. -1 means unlimited */ u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */ void *pUserData; /* User data parameter */ FuncDef *pNext; /* Next function with same name */ void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */ void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */ void (*xFinalize)(sqlite3_context*); /* Aggregate finializer */ u8 needCollSeq; /* True if sqlite3GetFuncCollSeq() might be called */};/*** information about each column of an SQL table is held in an instance** of this structure.*/struct Column { char *zName; /* Name of this column */ Expr *pDflt; /* Default value of this column */ char *zType; /* Data type for this column */ CollSeq *pColl; /* Collating sequence. If NULL, use the default */ u8 notNull; /* True if there is a NOT NULL constraint */ u8 isPrimKey; /* True if this column is part of the PRIMARY KEY */ char affinity; /* One of the SQLITE_AFF_... values */};/*** A "Collating Sequence" is defined by an instance of the following** structure. Conceptually, a collating sequence consists of a name and** a comparison routine that defines the order of that sequence.**** There may two seperate implementations of the collation function, one** that processes text in UTF-8 encoding (CollSeq.xCmp) and another that** processes text encoded in UTF-16 (CollSeq.xCmp16), using the machine** native byte order. When a collation sequence is invoked, SQLite selects** the version that will require the least expensive encoding** transalations, if any.**** The CollSeq.pUser member variable is an extra parameter that passed in** as the first argument to the UTF-8 comparison function, xCmp.** CollSeq.pUser16 is the equivalent for the UTF-16 comparison function,** xCmp16.**** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the** collating sequence is undefined. Indices built on an undefined** collating sequence may not be read or written.*/struct CollSeq { char *zName; /* Name of the collating sequence, UTF-8 encoded */ u8 enc; /* Text encoding handled by xCmp() */ void *pUser; /* First argument to xCmp() */ int (*xCmp)(void*,int, const void*, int, const void*);};/*** A sort order can be either ASC or DESC.*/#define SQLITE_SO_ASC 0 /* Sort in ascending order */#define SQLITE_SO_DESC 1 /* Sort in ascending order *//*** Column affinity types.*/#define SQLITE_AFF_INTEGER 'i'#define SQLITE_AFF_NUMERIC 'n'#define SQLITE_AFF_TEXT 't'#define SQLITE_AFF_NONE 'o'/*** Each SQL table is represented in memory by an instance of the** following structure.**** Table.zName is the name of the table. The case of the original** CREATE TABLE statement is stored, but case is not significant for** comparisons.**** Table.nCol is the number of columns in this table. Table.aCol is a** pointer to an array of Column structures, one for each column.**** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of** the column that is that key. Otherwise Table.iPKey is negative. Note** that the datatype of the PRIMARY KEY must be INTEGER for this field to** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid** is generated for each row of the table. Table.hasPrimKey is true if** the table has any PRIMARY KEY, INTEGER or otherwise.**** Table.tnum is the page number for the root BTree page of the table in the** database file. If Table.iDb is the index of the database table backend** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that** holds temporary tables and indices. If Table.isTransient** is true, then the table is stored in a file that is automatically deleted** when the VDBE cursor to the table is closed. In this case Table.tnum
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -