⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edbinit.h

📁 在VC6环境下开发
💻 H
📖 第 1 页 / 共 2 页
字号:
};

struct Index {
  char *zName;		/* Name of this index */
  int nColumn;		/* Number of columns in the table used by this index */
  int *aiColumn;	/* Which columns are used by this index.  1st is 0 */
  Table *pTable;	/* The SQL table being indexed */
  int tnum;			/* Page containing root of this index in database file */
  u8 unique;		/* unique index */
  u8 autoIndex;		/* True if is automatically created (ex: by UNIQUE) */
  Index *pNext;		/* The next index associated with the same table */
};
struct eDb{	
	char *zName;         /* Name of this database */
	Btree *pBt;
	BtCursor *pCur[MAX_CURSORS];
	Hash tblHash;        /* All tables indexed by name */
	Hash idxHash;        /* All (named) indices indexed by name */
	u8 inTrans;          /* 0: not writable.  1: Transaction.  2: Checkpoint */
	u16 flags;           /* Flags associated with this database */
	u8 safety_level;              /* How aggressive at synching data to disk */
	int nextRowid;                /* ROWID of most recent insert (see above) */
	u8 nextRowidValid;
	int cache_size;               /* Number of pages to use in the cache */
	int nTable;
};
struct Token {
	const char *z;      /* Text of the token.  Not NULL-terminated! */
	unsigned dyn  : 1;  /* True for malloced memory, false for static */
	unsigned n    : 31; /* Number of characters in this token */
};
/*
** Each node of an expression in the parse tree is an instance
** of this structure.
**
** Expr.op is the opcode.  The integer parser token codes are reused
** as opcodes here.  For example, the parser defines TK_GE to be an integer
** code representing the ">=" operator.  This same integer code is reused
** to represent the greater-than-or-equal-to operator in the expression
** tree.
**
** Expr.pRight and Expr.pLeft are subexpressions.  Expr.pList is a list
** of argument if the expression is a function.
**
** Expr.token is the operator token for this node.  For some expressions
** that have subexpressions, Expr.token can be the complete text that gave
** rise to the Expr.  In the latter case, the token is marked as being
** a compound token.
**
** An expression of the form ID or ID.ID refers to a column in a table.
** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is
** the integer cursor number of a VDBE cursor pointing to that table and
** Expr.iColumn is the column number for the specific column.  If the
** expression is used as a result in an aggregate SELECT, then the
** value is also stored in the Expr.iAgg column in the aggregate so that
** it can be accessed after all aggregates are computed.
**
** If the expression is a function, the Expr.iTable is an integer code
** representing which function.  If the expression is an unbound variable
** marker (a question mark character '?' in the original SQL) then the
** Expr.iTable holds the index number for that variable.
**
** The Expr.pSelect field points to a SELECT statement.  The SELECT might
** be the right operand of an IN operator.  Or, if a scalar SELECT appears
** in an expression the opcode is TK_SELECT and Expr.pSelect is the only
** operand.
*/
struct Expr {
	u8 op;					/* Operation performed by this node */
	u8 dataType;			/* Either eDb_SO_TEXT or eDb_SO_NUM */  
	Expr *pLeft, *pRight;	/* Left and right subnodes */
	ExprList *pList;		/* A list of expressions used as function arguments
							** or in "<expr> IN (<expr-list)" */
	Token token;			/* An operand token */
	Token span;				/* Complete text of the expression */
	int iIndex, tnum;				
	int iTable, iColumn;	/* When op==TK_COLUMN, then this expr node means the
							** iColumn-th field of the iTable-th table. */
	int iAgg;				/* When op==TK_COLUMN and pParse->useAgg==TRUE, pull
							** result from the iAgg-th element of the aggregator */
	Select *pSelect;		/* When the expression is a sub-select.  Also the
							** right side of "<expr> IN (<select>)" */
};
struct ExprList {
	int nExpr;				/* Number of expressions on the list */
	int nAlloc;				/* Number of entries allocated below */
	struct ExprList_item {
		Expr *pExpr;		/* The list of expressions */
		char *zName;		/* Token associated with this expression */
		u8 sortOrder;		/* 1 for DESC or 0 for ASC */
		u8 isAgg;			/* True if this is an aggregate like count(*) */
		u8 done;			/* A flag to indicate when processing is finished */
	} *a;					/* One entry for each expression */
};
/*
** An instance of this structure can hold a simple list of identifiers,
** such as the list "a,b,c" in the following statements:
**
**      INSERT INTO t(a,b,c) VALUES ...;
**      CREATE INDEX idx ON t(a,b,c);
**      CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...;
**
** The IdList.a.idx field is used when the IdList represents the list of
** column names after a table name in an INSERT statement.  In the statement
**
**     INSERT INTO t(a,b,c) ...
**
** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
*/
struct IdList {
	int nId;         /* Number of identifiers on the list */
	int nAlloc;      /* Number of entries allocated for a[] below */
	struct IdList_item {
		char *zName;      /* Name of the identifier */
		int idx;          /* Index in some Table.aCol[] of a column named zName */
	} *a;
};

struct IdExprList {
	IdList *pIdList;
	ExprList *pEList;
};
/*
** The following structure describes the FROM clause of a SELECT statement.
** Each table or subquery in the FROM clause is a separate element of
** the SrcList.a[] array.
**
** With the addition of multiple database support, the following structure
** can also be used to describe a particular table such as the table that
** is modified by an INSERT, DELETE, or UPDATE statement.  In standard SQL,
** such a table must be a simple name: ID.  But in eDb, the table can
** now be identified by a database name, a dot, then the table name: ID.ID.
*/
struct SrcList {
	u16 nSrc;        /* Number of tables or subqueries in the FROM clause */
	u16 nAlloc;      /* Number of entries allocated in a[] below */
	struct SrcList_item {
		char *zDatabase;  /* Name of database holding this table */
		char *zName;      /* Name of the table */
		char *zAlias;     /* The "B" part of a "A AS B" phrase.  zName is the "A" */
		Table *pTab;      /* An SQL table corresponding to zName */
		Select *pSelect;  /* A SELECT statement used in place of a table name */
		int jointype;     /* Type of join between this table and the next */
		int iCursor;      /* The VDBE cursor number used to access this table */
		Expr *pOn;        /* The ON clause of a join */
		IdList *pUsing;   /* The USING clause of a join */
	} a[3];               /* One entry for each identifier on the list */
};
struct Select {
	ExprList *pEList;      /* The fields of the result */
	u8 op;                 /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
	u8 isDistinct;         /* True if the DISTINCT keyword is present */
	SrcList *pSrc;         /* The FROM clause */
	Expr *pWhere;          /* The WHERE clause */
	ExprList *pGroupBy;    /* The GROUP BY clause */
	Expr *pHaving;         /* The HAVING clause */
	ExprList *pOrderBy;    /* The ORDER BY clause */
	Select *pPrior;        /* Prior select in a compound select statement */
	int nLimit, nOffset;   /* LIMIT and OFFSET values.  -1 means not used */
	int iLimit, iOffset;   /* Memory registers holding LIMIT & OFFSET counters */
	char *zSelect;         /* Complete text of the SELECT command */
};

struct Parser{
	eDb *db;				/* The main database structure */
	int rc;					/* Return code from execution */
	char *zErrMsg;			/* An error message */
	Token sErrToken;		/* The token at which the error occurred */
	Token sFirstToken;		/* The first token parsed */
	Token sLastToken;		/* The last token parsed */
	const char *zTail;		/* All SQL text past the last semicolon parsed */
	Table *pNewTable;		/* A table being constructed by CREATE TABLE */
	void *pResult;			/* a pointer to the paresed result*/	
	u8 colNamesSet;			/* TRUE after OP_ColumnName has been issued to pVdbe */
	u8 explain;				/* True if the EXPLAIN flag is found on the query */
	u8 nameClash;			/* A permanent table name clashes with temp table name */
	int nErr;				/* Number of errors seen */
	int nTab;				/* Number of previously allocated VDBE cursors */
	int nMem;				/* Number of memory cells used so far */
	int nSet;				/* Number of sets used so far */
	int nVar;				/* Number of '?' variables seen in the SQL so far */
};
/*
** when the sql statement is parsed,a ParseResult struct will be return to Parse.presult;
*/
#define Op_CreateTable	1
#define Op_CreateIndex	2
#define Op_DropTable	3
#define Op_DropIndex	4
#define Op_Insert		5
#define Op_Update		6
#define Op_Delete		7
#define Op_Select		8
struct ParseResult{
	int op;
	char *zSql;
	Table *pTable;
	Index *pIndex;
	SrcList *pSrc;
	IdList *pIdList;
	ExprList *pEList;
	Expr *pWhere;
	Select *pSelect;
};

struct KeyData{
	char *pKey;
	int nKey;
	char *pData;
	int nData;
};

/*
** this is a expr array devided by 'or'
*/
struct CExpr{
		Expr *pExpr;
		int op;
		int go;
		int next;
	};

struct WhereExpr{
	CExpr a[101];
	u8 useIndex;
	u8 nExpr;
};
void eDbUpdate(Parser *pParse,SrcList *pTabList, IdExprList *pChanges,Expr *pWhere);
extern WhereExpr aCExpr;


#endif /* _eDbInit_H_ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -