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 ***************************************************************************/
25 * @brief Represents the condition part of SQL Query.
26 * Used in SELECT, UPDATE and DELETE statement to retrieve only tuples which satisfy<br/>
27 * the condition. This represents the root of the logical expression. This logical <br/>
28 * expression may contain multiple terms(predicates).<br/>
29 * For example to set this condition f1 == f2 && f1 == 100. <br/>
31 * int val1 = 100;<br/>
32 * c1.setTerm("f1", OpEquals, &val1);<br/>
33 * Predicate *p1 = c1.getPredicate();<br/>
35 * c2.setTerm("f1", opEquals, "f2");<br/>
36 * Predicate *p2 = c2.getPredicate();<br/>
37 * Condtion rootCondition;<br/>
38 * rootCondition.setTerm(p1, OpAnd, p2);<br/>
39 * table->setCondition(rootCondition);<br/>
40 * @author Prabakaran Thirumalai
49 /** gets the current predicate. This is used to create logical expressions with terms or predicates.
50 * @return Predicate* predicate
52 Predicate
* getPredicate() { return pred
; }
53 /** sets the predicate term of form f1 = f2.
54 * @param fName1* field name
55 * @param op comparision operator
56 * @param fName2* field name
58 void setTerm(const char* fName1
, ComparisionOp op
, const char *fName2
);
60 /** sets the predicate term of form f1 = 10
61 * @param fName1* field name
62 * @param op comparision operator(=,!=, >,<,>=,<=)
63 * @param opnd* pointer to the value
65 void setTerm(const char* fName1
, ComparisionOp op
, void *opnd
);
67 /** sets the predicate term of form f1 = f2 && f1 = 100.
68 * @param p1* predicate
69 * @param op logical operator (&&, ||, !)
70 * @param p2* predicate
72 void setTerm(Predicate
*p1
, LogicalOp op
, Predicate
*p2
= NULL
);
79 * @brief Represents a single term in the condition.
80 * Condition is logical expression composed of terms and logical operators. This
81 * represents the leaf of the logical expression tree. This is designed using composite
84 * @author Prabakaran Thirumalai
89 virtual void setTerm(const char* fName1
, ComparisionOp op
, const char *fName2
)=0;
91 //Operand should be of the same type of the field. This is must
92 virtual void setTerm(const char* fName1
, ComparisionOp op
, void *opnd
)=0;
94 virtual void setTerm(Predicate
*p1
, LogicalOp op
, Predicate
*p2
= NULL
)=0;
95 virtual ~Predicate(){}