📄 where.c
字号:
#include "eDbInit.h"
int eDbExprSplit(CExpr *aCE, Expr *pExpr, int nSlot, int base);
WhereExpr aCExpr;
#define ARRAYSIZE(X) (sizeof(X)/sizeof(X[0]))
/*
** This routine is used to divide the WHERE expression into subexpressions
** separated by the OR operator.
**
** aSlot[] is an array of subexpressions structures.
** There are nSlot spaces left in this array. This routine attempts to
** split pExpr into subexpressions and fills aSlot[] with those subexpressions.
** The return value is the number of slots filled.
*/
int eDbDealwithWhereClause(SrcList *pSrc,Expr *pWhere){
int nExpr;
int n;
memset(&aCExpr,0,sizeof(aCExpr));
n = ARRAYSIZE(aCExpr.a);
nExpr = eDbExprSplit(aCExpr.a,pWhere,n,0);
aCExpr.nExpr = nExpr;
return eDb_OK;
}
/*
** Generate code for a boolean expression such that a jump is made
** to the label "dest" if the expression is false but execution
** continues straight thru if the expression is true.
**
** If the expression evaluates to NULL (neither true nor false) then
** jump if jumpIfNull is true or fall through if jumpIfNull is false.
*/
int eDbExprSplit(CExpr *aCE, Expr *pExpr, int nSlot, int base){
int nExpr;
int cnt;
if( pExpr==0 || nSlot<1 ) return 0;
if( nSlot==1 ){
aCE[0].pExpr = pExpr;
return 1;
}
switch( pExpr->op ){
case TK_AND: {
nExpr = eDbExprSplit(aCE, pExpr->pLeft, nSlot, base);
aCE[nExpr-1].op = TK_AND;
aCE[nExpr-1].next = nExpr + base;
cnt = nExpr-1;
nExpr += eDbExprSplit(&aCE[nExpr], pExpr->pRight, nSlot-nExpr, nExpr+base);
aCE[cnt].go = nExpr + base;
break;
}
case TK_OR: {
nExpr = eDbExprSplit(aCE, pExpr->pLeft, nSlot, base);
aCE[nExpr-1].op = TK_OR;
aCE[nExpr-1].next = nExpr + base;
cnt = nExpr-1;
nExpr += eDbExprSplit(&aCE[nExpr], pExpr->pRight, nSlot-nExpr, nExpr+base);
aCE[cnt].go = nExpr + base;
break;
}
case TK_LT:
case TK_LE:
case TK_GT:
case TK_GE:
case TK_NE:
case TK_EQ:{
aCE[0].pExpr = pExpr;
return 1;
break;
}
default: {
assert(0);
}
}
return nExpr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -