icsql with no dependency on readline library
[csql.git] / include / PredicateImpl.h
bloba37a4aff41bfda23ebbeb26213c0ba01427f701b
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #ifndef PREDICATE_IMPL_H
17 #define PREDICATE_IMPL_H
18 #include<DataType.h>
19 #include<Predicate.h>
20 #include<ErrorType.h>
21 class TableImpl;
22 class Table;
23 class List;
24 class AggTableImpl;
25 class DllExport PredicateImpl:public Predicate
27 //Members set during initialization of the term
28 char fldName1[IDENTIFIER_LENGTH];
29 char fldName2[IDENTIFIER_LENGTH];
30 ComparisionOp compOp;
31 void *operand;
32 void **operandPtr;
33 LogicalOp logicalOp;
34 PredicateImpl *lhs;
35 PredicateImpl *rhs;
36 PredicateImpl *parent;
37 int offset1,offset2;
38 DataType type;
39 int length;
40 bool isNullable;
41 int fldPos;
42 //Members set during execution
43 void *tuple; //pointer to the tuple
44 List *projList;
45 bool isPushedDown;
46 AggType aggType;
47 //optimization:caching val1 and val2 for evaluation
48 char *val1;
49 char *val2;
50 char *val3;
51 bool isBindBufSet;
52 bool isNoLeftRight;
53 bool dontEvaluate;
54 Expression *lExp;
55 Expression *rExp;
56 //opt for between queries
57 ComparisionOp comp2Op;
58 void *operand2;
59 void **operand2Ptr;
60 //This will be set before calling evaluate
61 Table *table;
62 bool isNull;
63 public:
64 PredicateImpl()
66 strcpy(fldName1, ""); strcpy(fldName2, "");
67 lhs = rhs = NULL;
68 tuple = NULL; table = NULL;
69 projList = NULL;
70 parent = NULL;
71 offset1 = -1; offset2 =-1;
72 type = typeUnknown; length = 0;
73 isPushedDown=false;
74 isBindBufSet = false;
75 val1= NULL; val2=NULL; val3=NULL;
76 isNoLeftRight=false;
77 dontEvaluate=false;
78 aggType = AGG_UNKNOWN;
79 operand2 = operand = NULL;
80 operand2Ptr = operandPtr= NULL;
81 compOp = comp2Op = OpInvalidComparisionOp;
82 logicalOp = OpInvalidLogicalOp;
83 isNull=false;
84 lExp = NULL; rExp = NULL;
86 ~PredicateImpl();
88 void setTerm(const char* fName1, ComparisionOp op, const char *fName2);
90 //Operand should be of the same type of the field.This is must
91 void setTerm(const char* fName1, ComparisionOp op, void *opnd);
93 void setTerm(const char* fName1, ComparisionOp op, void **opnd);
94 void setTerm(const char* fName1, ComparisionOp op, void **opnd, AggType aggType);
95 void setTerm(const char* fName1, ComparisionOp op, void **opnd,
96 ComparisionOp op2, void **opnd2 );
99 void setTerm(Predicate *p1, LogicalOp op, Predicate *p2 = NULL);
100 void setTerm(Expression *exp, ComparisionOp op, void **opnd);
101 void setTerm(Expression *exp, ComparisionOp op, const char *fName2);
102 void setTerm(Expression *exp1, ComparisionOp op, Expression *exp2);
103 void setTerm(const char* fName1, ComparisionOp op,bool nullFlag);
104 void* valPtrForIndexField(const char *name, bool isUnique);
105 ComparisionOp opForIndexField(const char *name);
106 void* opAndValPtrForIndexField(const char *name, bool isUnique,ComparisionOp &op);
107 DbRetVal evaluate(bool &result);
108 void evaluateForTable(bool &result, char*tuple);
109 DbRetVal evaluateForHaving(bool &result, AggTableImpl *aImpl, void* elem);
111 DbRetVal evaluateLogical(bool &result);
112 DbRetVal evaluateLogicalForTable(bool &result, char *tuple);
113 DbRetVal evaluateLogicalForHaving(bool &result, AggTableImpl *aImpl, void* elem);
115 void setTable(Table *tbl);
116 void setTuple(void *tpl);
117 void setProjectionList(List *list); //used by JoinTableImpl
118 void setOffsetAndType();
119 bool isSingleTerm();
120 bool isNotOrInvolved();
121 bool isIsNullInvolved();
122 //check predicate, whether it has field name and == operator
123 //and does not have OR, NOT operator
124 // TODO:: expression like !(f1 !=100) wont be optimized for now
125 bool pointLookupInvolved(const char *fName);
126 bool rangeQueryInvolved(const char *fName);
127 bool isBetweenInvolved(const char *fname);
128 PredicateImpl *getTablePredicate();
129 PredicateImpl *getJoinPredicate();
130 void removeIfNotNecessary();
131 bool isDummyPredicate();
132 PredicateImpl* getIfOneSidedPredicate();
133 void setParent(PredicateImpl *pImpl);
134 char* getFldName1(){ return fldName1; }
135 char* getFldName2(){ return fldName2; }
136 ComparisionOp getCompOp() {return compOp; }
137 void print(int space);
138 void setIfNoLeftRight();
139 void setDontEvaluate(){dontEvaluate = true;}
140 bool appendIfSameFld(char *fname, ComparisionOp op, void* buf);
141 void* getValIfPointLookupOnInt(int &offset);
142 void* getVal1IfBetweenOnInt(int &offset);
143 void* getVal2IfBetweenOnInt(int &offset);
144 void solveForProjList(Table *tab);
147 #endif