1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: * Contact: praba_tuty@databasecache.com *
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. *
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. *
16 ***************************************************************************/
19 #include<Expression.h>
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/>
46 * int val1 = 100;<br/>
47 * c1.setTerm("f1", OpEquals, &val1);<br/>
48 * Predicate *p1 = c1.getPredicate();<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
65 /** gets the current predicate. This is used to create logical expressions with terms or predicates.
66 * @return Predicate* predicate
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
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
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
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
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
);
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
118 class DllExport Predicate
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(){}