table->closeScan is called instead of close
[csql.git] / include / PredicateImpl.h
blob7917ce0c14daca6d4d3d3dd79caba1c64c81ddf0
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 PredicateImpl:public Predicate
26 //Members set during initialization of the term
27 char fldName1[IDENTIFIER_LENGTH];
28 char fldName2[IDENTIFIER_LENGTH];
29 ComparisionOp compOp;
30 void *operand;
31 void **operandPtr;
32 LogicalOp logicalOp;
33 PredicateImpl *lhs;
34 PredicateImpl *rhs;
35 PredicateImpl *parent;
36 int offset1,offset2;
37 DataType type;
38 int length;
39 //Members set during execution
40 void *tuple; //pointer to the tuple
41 List *projList;
42 bool isPushedDown;
44 //optimization:caching val1 and val2 for evaluation
45 char *val1;
46 char *val2;
47 bool isBindBufSet;
48 bool isNoLeftRight;
50 //This will be set before calling evaluate
51 TableImpl *table;
53 public:
54 PredicateImpl()
56 strcpy(fldName1, ""); strcpy(fldName2, "");
57 operand = NULL; operandPtr = NULL; lhs = rhs = NULL;
58 tuple = NULL; table = NULL;
59 projList = NULL;
60 parent = NULL;
61 offset1 = -1; offset2 =-1;
62 type = typeUnknown;
63 length = 0;
64 isPushedDown=false;
65 isBindBufSet = false;
66 val1= NULL;
67 val2=NULL;
68 isNoLeftRight=false;
70 ~PredicateImpl(){}
72 void setTerm(const char* fName1, ComparisionOp op, const char *fName2);
74 //Operand should be of the same type of the field.This is must
75 void setTerm(const char* fName1, ComparisionOp op, void *opnd);
77 void setTerm(const char* fName1, ComparisionOp op, void **opnd);
80 void setTerm(Predicate *p1, LogicalOp op, Predicate *p2 = NULL);
82 void* valPtrForIndexField(const char *name);
83 ComparisionOp opForIndexField(const char *name);
85 DbRetVal evaluate(bool &result);
87 void setTable(Table *tbl);
88 void setTuple(void *tpl);
89 void setProjectionList(List *list); //used by JoinTableImpl
90 void setOffsetAndType();
91 bool isSingleTerm();
92 bool isNotOrInvolved();
93 //check predicate, whether it has field name and == operator
94 //and does not have OR, NOT operator
95 // TODO:: expression like !(f1 !=100) wont be optimized for now
96 bool pointLookupInvolved(const char *fName);
97 bool rangeQueryInvolved(const char *fName);
98 bool isBetweenInvolved(const char *fname);
99 PredicateImpl *getTablePredicate();
100 PredicateImpl *getJoinPredicate();
101 void removeIfNotNecessary();
102 bool isDummyPredicate();
103 PredicateImpl* getIfOneSidedPredicate();
104 void setParent(PredicateImpl *pImpl);
105 char* getFldName1(){ return fldName1; }
106 char* getFldName2(){ return fldName2; }
107 ComparisionOp getCompOp() {return compOp; }
108 void print(int space);
109 void setIfNoLeftRight();
112 #endif