📄 sqliteint.h
字号:
* * Pointers to instances of struct Trigger are stored in two ways. * 1. In the "trigHash" hash table (part of the sqlite* that represents the * database). This allows Trigger structures to be retrieved by name. * 2. All triggers associated with a single table form a linked list, using the * pNext member of struct Trigger. A pointer to the first element of the * linked list is stored as the "pTrigger" member of the associated * struct Table. * * The "step_list" member points to the first element of a linked list * containing the SQL statements specified as the trigger program. */struct Trigger { char *name; /* The name of the trigger */ char *table; /* The table or view to which the trigger applies */ u8 iDb; /* Database containing this trigger */ u8 iTabDb; /* Database containing Trigger.table */ u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */ u8 tr_tm; /* One of TK_BEFORE, TK_AFTER */ Expr *pWhen; /* The WHEN clause of the expresion (may be NULL) */ IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger, the <column-list> is stored here */ int foreach; /* One of TK_ROW or TK_STATEMENT */ Token nameToken; /* Token containing zName. Use during parsing only */ TriggerStep *step_list; /* Link list of trigger program steps */ Trigger *pNext; /* Next trigger associated with the table */};/* * An instance of struct TriggerStep is used to store a single SQL statement * that is a part of a trigger-program. * * Instances of struct TriggerStep are stored in a singly linked list (linked * using the "pNext" member) referenced by the "step_list" member of the * associated struct Trigger instance. The first element of the linked list is * the first step of the trigger-program. * * The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or * "SELECT" statement. The meanings of the other members is determined by the * value of "op" as follows: * * (op == TK_INSERT) * orconf -> stores the ON CONFLICT algorithm * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then * this stores a pointer to the SELECT statement. Otherwise NULL. * target -> A token holding the name of the table to insert into. * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then * this stores values to be inserted. Otherwise NULL. * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ... * statement, then this stores the column-names to be * inserted into. * * (op == TK_DELETE) * target -> A token holding the name of the table to delete from. * pWhere -> The WHERE clause of the DELETE statement if one is specified. * Otherwise NULL. * * (op == TK_UPDATE) * target -> A token holding the name of the table to update rows of. * pWhere -> The WHERE clause of the UPDATE statement if one is specified. * Otherwise NULL. * pExprList -> A list of the columns to update and the expressions to update * them to. See sqliteUpdate() documentation of "pChanges" * argument. * */struct TriggerStep { int op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */ int orconf; /* OE_Rollback etc. */ Trigger *pTrig; /* The trigger that this step is a part of */ Select *pSelect; /* Valid for SELECT and sometimes INSERT steps (when pExprList == 0) */ Token target; /* Valid for DELETE, UPDATE, INSERT steps */ Expr *pWhere; /* Valid for DELETE, UPDATE steps */ ExprList *pExprList; /* Valid for UPDATE statements and sometimes INSERT steps (when pSelect == 0) */ IdList *pIdList; /* Valid for INSERT statements only */ TriggerStep * pNext; /* Next in the link-list */};/* * An instance of struct TriggerStack stores information required during code * generation of a single trigger program. While the trigger program is being * coded, its associated TriggerStack instance is pointed to by the * "pTriggerStack" member of the Parse structure. * * The pTab member points to the table that triggers are being coded on. The * newIdx member contains the index of the vdbe cursor that points at the temp * table that stores the new.* references. If new.* references are not valid * for the trigger being coded (for example an ON DELETE trigger), then newIdx * is set to -1. The oldIdx member is analogous to newIdx, for old.* references. * * The ON CONFLICT policy to be used for the trigger program steps is stored * as the orconf member. If this is OE_Default, then the ON CONFLICT clause * specified for individual triggers steps is used. * * struct TriggerStack has a "pNext" member, to allow linked lists to be * constructed. When coding nested triggers (triggers fired by other triggers) * each nested trigger stores its parent trigger's TriggerStack as the "pNext" * pointer. Once the nested trigger has been coded, the pNext value is restored * to the pTriggerStack member of the Parse stucture and coding of the parent * trigger continues. * * Before a nested trigger is coded, the linked list pointed to by the * pTriggerStack is scanned to ensure that the trigger is not about to be coded * recursively. If this condition is detected, the nested trigger is not coded. */struct TriggerStack { Table *pTab; /* Table that triggers are currently being coded on */ int newIdx; /* Index of vdbe cursor to "new" temp table */ int oldIdx; /* Index of vdbe cursor to "old" temp table */ int orconf; /* Current orconf policy */ int ignoreJump; /* where to jump to for a RAISE(IGNORE) */ Trigger *pTrigger; /* The trigger currently being coded */ TriggerStack *pNext; /* Next trigger down on the trigger stack */};/*** The following structure contains information used by the sqliteFix...** routines as they walk the parse tree to make database references** explicit. */typedef struct DbFixer DbFixer;struct DbFixer { Parse *pParse; /* The parsing context. Error messages written here */ const char *zDb; /* Make sure all objects are contained in this database */ const char *zType; /* Type of the container - used for error messages */ const Token *pName; /* Name of the container - used for error messages */};/* * This global flag is set for performance testing of triggers. When it is set * SQLite will perform the overhead of building new and old trigger references * even when no triggers exist */extern int always_code_trigger_setup;/*** Internal function prototypes*/int sqliteStrICmp(const char *, const char *);int sqliteStrNICmp(const char *, const char *, int);int sqliteHashNoCase(const char *, int);int sqliteIsNumber(const char*);int sqliteCompare(const char *, const char *);int sqliteSortCompare(const char *, const char *);void sqliteRealToSortable(double r, char *);#ifdef MEMORY_DEBUG void *sqliteMalloc_(int,int,char*,int); void sqliteFree_(void*,char*,int); void *sqliteRealloc_(void*,int,char*,int); char *sqliteStrDup_(const char*,char*,int); char *sqliteStrNDup_(const char*, int,char*,int); void sqliteCheckMemory(void*,int);#else void *sqliteMalloc(int); void *sqliteMallocRaw(int); void sqliteFree(void*); void *sqliteRealloc(void*,int); char *sqliteStrDup(const char*); char *sqliteStrNDup(const char*, int);# define sqliteCheckMemory(a,b)#endifchar *sqliteMPrintf(const char*, ...);char *sqliteVMPrintf(const char*, va_list);void sqliteSetString(char **, ...);void sqliteSetNString(char **, ...);void sqliteErrorMsg(Parse*, const char*, ...);void sqliteDequote(char*);int sqliteKeywordCode(const char*, int);int sqliteRunParser(Parse*, const char*, char **);void sqliteExec(Parse*);Expr *sqliteExpr(int, Expr*, Expr*, Token*);void sqliteExprSpan(Expr*,Token*,Token*);Expr *sqliteExprFunction(ExprList*, Token*);void sqliteExprDelete(Expr*);ExprList *sqliteExprListAppend(ExprList*,Expr*,Token*);void sqliteExprListDelete(ExprList*);int sqliteInit(sqlite*, char**);void sqlitePragma(Parse*,Token*,Token*,int);void sqliteResetInternalSchema(sqlite*, int);void sqliteBeginParse(Parse*,int);void sqliteRollbackInternalChanges(sqlite*);void sqliteCommitInternalChanges(sqlite*);Table *sqliteResultSetOfSelect(Parse*,char*,Select*);void sqliteOpenMasterTable(Vdbe *v, int);void sqliteStartTable(Parse*,Token*,Token*,int,int);void sqliteAddColumn(Parse*,Token*);void sqliteAddNotNull(Parse*, int);void sqliteAddPrimaryKey(Parse*, IdList*, int);void sqliteAddColumnType(Parse*,Token*,Token*);void sqliteAddDefaultValue(Parse*,Token*,int);int sqliteCollateType(const char*, int);void sqliteAddCollateType(Parse*, int);void sqliteEndTable(Parse*,Token*,Select*);void sqliteCreateView(Parse*,Token*,Token*,Select*,int);int sqliteViewGetColumnNames(Parse*,Table*);void sqliteDropTable(Parse*, Token*, int);void sqliteDeleteTable(sqlite*, Table*);void sqliteInsert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);IdList *sqliteIdListAppend(IdList*, Token*);int sqliteIdListIndex(IdList*,const char*);SrcList *sqliteSrcListAppend(SrcList*, Token*, Token*);void sqliteSrcListAddAlias(SrcList*, Token*);void sqliteSrcListAssignCursors(Parse*, SrcList*);void sqliteIdListDelete(IdList*);void sqliteSrcListDelete(SrcList*);void sqliteCreateIndex(Parse*,Token*,SrcList*,IdList*,int,Token*,Token*);void sqliteDropIndex(Parse*, SrcList*);void sqliteAddKeyType(Vdbe*, ExprList*);void sqliteAddIdxKeyType(Vdbe*, Index*);int sqliteSelect(Parse*, Select*, int, int, Select*, int, int*);Select *sqliteSelectNew(ExprList*,SrcList*,Expr*,ExprList*,Expr*,ExprList*, int,int,int);void sqliteSelectDelete(Select*);void sqliteSelectUnbind(Select*);Table *sqliteSrcListLookup(Parse*, SrcList*);int sqliteIsReadOnly(Parse*, Table*, int);void sqliteDeleteFrom(Parse*, SrcList*, Expr*);void sqliteUpdate(Parse*, SrcList*, ExprList*, Expr*, int);WhereInfo *sqliteWhereBegin(Parse*, SrcList*, Expr*, int, ExprList**);void sqliteWhereEnd(WhereInfo*);void sqliteExprCode(Parse*, Expr*);int sqliteExprCodeExprList(Parse*, ExprList*, int);void sqliteExprIfTrue(Parse*, Expr*, int, int);void sqliteExprIfFalse(Parse*, Expr*, int, int);Table *sqliteFindTable(sqlite*,const char*, const char*);Table *sqliteLocateTable(Parse*,const char*, const char*);Index *sqliteFindIndex(sqlite*,const char*, const char*);void sqliteUnlinkAndDeleteIndex(sqlite*,Index*);void sqliteCopy(Parse*, SrcList*, Token*, Token*, int);void sqliteVacuum(Parse*, Token*);int sqliteRunVacuum(char**, sqlite*);int sqliteGlobCompare(const unsigned char*,const unsigned char*);int sqliteLikeCompare(const unsigned char*,const unsigned char*);char *sqliteTableNameFromToken(Token*);int sqliteExprCheck(Parse*, Expr*, int, int*);int sqliteExprType(Expr*);int sqliteExprCompare(Expr*, Expr*);int sqliteFuncId(Token*);int sqliteExprResolveIds(Parse*, SrcList*, ExprList*, Expr*);int sqliteExprAnalyzeAggregates(Parse*, Expr*);Vdbe *sqliteGetVdbe(Parse*);void sqliteRandomness(int, void*);void sqliteRollbackAll(sqlite*);void sqliteCodeVerifySchema(Parse*, int);void sqliteBeginTransaction(Parse*, int);void sqliteCommitTransaction(Parse*);void sqliteRollbackTransaction(Parse*);int sqliteExprIsConstant(Expr*);int sqliteExprIsInteger(Expr*, int*);int sqliteIsRowid(const char*);void sqliteGenerateRowDelete(sqlite*, Vdbe*, Table*, int, int);void sqliteGenerateRowIndexDelete(sqlite*, Vdbe*, Table*, int, char*);void sqliteGenerateConstraintChecks(Parse*,Table*,int,char*,int,int,int,int);void sqliteCompleteInsertion(Parse*, Table*, int, char*, int, int, int);int sqliteOpenTableAndIndices(Parse*, Table*, int);void sqliteBeginWriteOperation(Parse*, int, int);void sqliteEndWriteOperation(Parse*);Expr *sqliteExprDup(Expr*);void sqliteTokenCopy(Token*, Token*);ExprList *sqliteExprListDup(ExprList*);SrcList *sqliteSrcListDup(SrcList*);IdList *sqliteIdListDup(IdList*);Select *sqliteSelectDup(Select*);FuncDef *sqliteFindFunction(sqlite*,const char*,int,int,int);void sqliteRegisterBuiltinFunctions(sqlite*);void sqliteRegisterDateTimeFunctions(sqlite*);int sqliteSafetyOn(sqlite*);int sqliteSafetyOff(sqlite*);int sqliteSafetyCheck(sqlite*);void sqliteChangeCookie(sqlite*, Vdbe*);void sqliteBeginTrigger(Parse*, Token*,int,int,IdList*,SrcList*,int,Expr*,int);void sqliteFinishTrigger(Parse*, TriggerStep*, Token*);void sqliteDropTrigger(Parse*, SrcList*);void sqliteDropTriggerPtr(Parse*, Trigger*, int);int sqliteTriggersExist(Parse* , Trigger* , int , int , int, ExprList*);int sqliteCodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int, int, int);void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);void sqliteDeleteTriggerStep(TriggerStep*);TriggerStep *sqliteTriggerSelectStep(Select*);TriggerStep *sqliteTriggerInsertStep(Token*, IdList*, ExprList*, Select*, int);TriggerStep *sqliteTriggerUpdateStep(Token*, ExprList*, Expr*, int);TriggerStep *sqliteTriggerDeleteStep(Token*, Expr*);void sqliteDeleteTrigger(Trigger*);int sqliteJoinType(Parse*, Token*, Token*, Token*);void sqliteCreateForeignKey(Parse*, IdList*, Token*, IdList*, int);void sqliteDeferForeignKey(Parse*, int);#ifndef SQLITE_OMIT_AUTHORIZATION void sqliteAuthRead(Parse*,Expr*,SrcList*); int sqliteAuthCheck(Parse*,int, const char*, const char*, const char*); void sqliteAuthContextPush(Parse*, AuthContext*, const char*); void sqliteAuthContextPop(AuthContext*);#else# define sqliteAuthRead(a,b,c)# define sqliteAuthCheck(a,b,c,d,e) SQLITE_OK# define sqliteAuthContextPush(a,b,c)# define sqliteAuthContextPop(a) ((void)(a))#endifvoid sqliteAttach(Parse*, Token*, Token*, Token*);void sqliteDetach(Parse*, Token*);int sqliteBtreeFactory(const sqlite *db, const char *zFilename, int mode, int nPg, Btree **ppBtree);int sqliteFixInit(DbFixer*, Parse*, int, const char*, const Token*);int sqliteFixSrcList(DbFixer*, SrcList*);int sqliteFixSelect(DbFixer*, Select*);int sqliteFixExpr(DbFixer*, Expr*);int sqliteFixExprList(DbFixer*, ExprList*);int sqliteFixTriggerStep(DbFixer*, TriggerStep*);double sqliteAtoF(const char *z, const char **);char *sqlite_snprintf(int,char*,const char*,...);int sqliteFitsIn32Bits(const char *);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -