test cases for trie index
[csql.git] / include / Predicate.h
blob9ff7f8859ee4aa423c6c73ff978d769f59adc2e3
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: * Contact: praba_tuty@databasecache.com *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 ***************************************************************************/
17 #ifndef PREDICATE_H
18 #define PREDICATE_H
19 #include<Expression.h>
20 #include<DataType.h>
21 class PredicateImpl;
22 class Predicate;
23 #ifndef AGGTYPE
24 enum AggType
26 AGG_MIN = 1,
27 AGG_MAX,
28 AGG_SUM,
29 AGG_AVG,
30 AGG_COUNT,
31 AGG_UNKNOWN
33 #define AGGTYPE
34 #endif
37 /**
38 * @class Condition
40 * @brief Represents the condition part of SQL Query.
41 * Used in SELECT, UPDATE and DELETE statement to retrieve only tuples which satisfy<br/>
42 * the condition. This represents the root of the logical expression. This logical <br/>
43 * expression may contain multiple terms(predicates).<br/>
44 * For example to set this condition f1 == f2 && f1 == 100. <br/>
45 * Condition c1;<br/>
46 * int val1 = 100;<br/>
47 * c1.setTerm("f1", OpEquals, &val1);<br/>
48 * Predicate *p1 = c1.getPredicate();<br/>
49 * Condition c2;<br/>
50 * c2.setTerm("f1", opEquals, "f2");<br/>
51 * Predicate *p2 = c2.getPredicate();<br/>
52 * Condtion rootCondition;<br/>
53 * rootCondition.setTerm(p1, OpAnd, p2);<br/>
54 * table->setCondition(rootCondition);<br/>
57 class DllExport Condition
59 Predicate *pred;
60 public:
61 Condition();
62 ~Condition();
63 void reset();
65 /** gets the current predicate. This is used to create logical expressions with terms or predicates.
66 * @return Predicate* predicate
67 */
68 Predicate* getPredicate() { return pred; }
70 /** sets the current predicate. This is set after creating the logical expression and used in the table interface for setting the condition.
71 * @param Predicate* predicate
72 */
73 void setPredicate(Predicate * predicate) { pred = predicate; }
76 /** sets the predicate term of form f1 = f2.
77 * @param fName1* field name
78 * @param op comparision operator
79 * @param fName2* field name
80 */
81 void setTerm(const char* fName1, ComparisionOp op, const char *fName2);
83 /** sets the predicate term of form f1 = 10
84 * @param fName1* field name
85 * @param op comparision operator(=,!=, >,<,>=,<=)
86 * @param opnd* pointer to the value
87 */
88 void setTerm(const char* fName1, ComparisionOp op, void *opnd);
90 /** sets the predicate term of form f1 =10, using pointer semantics
91 * @param fName1* field name
92 * @param op comparision operator(=,!=, >,<,>=,<=)
93 * @param opnd** pointer to pointer to the value
94 */
95 void setTerm(const char* fName1, ComparisionOp op, void **opnd );
96 void setTerm(const char* fName1, ComparisionOp op, void **opnd, AggType aggType);
99 /** sets the predicate term of form f1 = f2 && f1 = 100.
100 * @param p1* predicate
101 * @param op logical operator (&&, ||, !)
102 * @param p2* predicate
104 void setTerm(Predicate *p1, LogicalOp op, Predicate *p2 = NULL);
109 * @class Predicate
111 * @brief Represents a single term in the condition.
112 * Condition is logical expression composed of terms and logical operators. This
113 * represents the leaf of the logical expression tree. This is designed using composite
114 * design pattern
118 class DllExport Predicate
120 public:
121 virtual void setTerm(const char* fName1, ComparisionOp op, const char *fName2)=0;
123 //Operand should be of the same type of the field. This is must
124 virtual void setTerm(const char* fName1, ComparisionOp op, void *opnd)=0;
126 //Operand should be of the same type of the field. This is must
127 virtual void setTerm(const char* fName1, ComparisionOp op, void **opnd)=0;
129 virtual void setTerm(Predicate *p1, LogicalOp op, Predicate *p2 = NULL)=0;
130 virtual void setTerm(const char* fName1, ComparisionOp op,bool nullFlag)=0;
131 virtual void setTerm(Expression *exp, ComparisionOp op, void **opnd) = 0;
132 virtual void setTerm(Expression *exp, ComparisionOp op, const char *fName2) = 0;
133 virtual void setTerm(Expression *exp1, ComparisionOp op, Expression *exp2) = 0;
134 virtual void print(int space)=0;
135 virtual ~Predicate(){}
139 #endif