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
; }
54 /** sets the current predicate. This is set after creating the logical expression and used in the table interface for setting the condition.
55 * @param Predicate* predicate
57 void setPredicate(Predicate
* predicate
) { pred
= predicate
; }
60 /** sets the predicate term of form f1 = f2.
61 * @param fName1* field name
62 * @param op comparision operator
63 * @param fName2* field name
65 void setTerm(const char* fName1
, ComparisionOp op
, const char *fName2
);
67 /** sets the predicate term of form f1 = 10
68 * @param fName1* field name
69 * @param op comparision operator(=,!=, >,<,>=,<=)
70 * @param opnd* pointer to the value
72 void setTerm(const char* fName1
, ComparisionOp op
, void *opnd
);
74 /** sets the predicate term of form f1 =10, using pointer semantics
75 * @param fName1* field name
76 * @param op comparision operator(=,!=, >,<,>=,<=)
77 * @param opnd** pointer to pointer to the value
79 void setTerm(const char* fName1
, ComparisionOp op
, void **opnd
);
82 /** sets the predicate term of form f1 = f2 && f1 = 100.
83 * @param p1* predicate
84 * @param op logical operator (&&, ||, !)
85 * @param p2* predicate
87 void setTerm(Predicate
*p1
, LogicalOp op
, Predicate
*p2
= NULL
);
94 * @brief Represents a single term in the condition.
95 * Condition is logical expression composed of terms and logical operators. This
96 * represents the leaf of the logical expression tree. This is designed using composite
99 * @author Prabakaran Thirumalai
104 virtual void setTerm(const char* fName1
, ComparisionOp op
, const char *fName2
)=0;
106 //Operand should be of the same type of the field. This is must
107 virtual void setTerm(const char* fName1
, ComparisionOp op
, void *opnd
)=0;
109 //Operand should be of the same type of the field. This is must
110 virtual void setTerm(const char* fName1
, ComparisionOp op
, void **opnd
)=0;
112 virtual void setTerm(Predicate
*p1
, LogicalOp op
, Predicate
*p2
= NULL
)=0;
114 virtual void print()=0;
115 virtual ~Predicate(){}