using tree index
[csql.git] / include / Predicate.h
blob3b69a6c8d9fc0e8c458cc3ae4efdaa53c5f77ce9
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<DataType.h>
20 class PredicateImpl;
21 class Predicate;
22 /**
23 * @class Condition
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/>
30 * Condition c1;<br/>
31 * int val1 = 100;<br/>
32 * c1.setTerm("f1", OpEquals, &val1);<br/>
33 * Predicate *p1 = c1.getPredicate();<br/>
34 * Condition c2;<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/>
42 class Condition
44 Predicate *pred;
45 public:
46 Condition();
47 ~Condition();
48 void reset();
50 /** gets the current predicate. This is used to create logical expressions with terms or predicates.
51 * @return Predicate* predicate
52 */
53 Predicate* getPredicate() { return pred; }
55 /** sets the current predicate. This is set after creating the logical expression and used in the table interface for setting the condition.
56 * @param Predicate* predicate
57 */
58 void setPredicate(Predicate * predicate) { pred = predicate; }
61 /** sets the predicate term of form f1 = f2.
62 * @param fName1* field name
63 * @param op comparision operator
64 * @param fName2* field name
65 */
66 void setTerm(const char* fName1, ComparisionOp op, const char *fName2);
68 /** sets the predicate term of form f1 = 10
69 * @param fName1* field name
70 * @param op comparision operator(=,!=, >,<,>=,<=)
71 * @param opnd* pointer to the value
72 */
73 void setTerm(const char* fName1, ComparisionOp op, void *opnd);
75 /** sets the predicate term of form f1 =10, using pointer semantics
76 * @param fName1* field name
77 * @param op comparision operator(=,!=, >,<,>=,<=)
78 * @param opnd** pointer to pointer to the value
79 */
80 void setTerm(const char* fName1, ComparisionOp op, void **opnd);
83 /** sets the predicate term of form f1 = f2 && f1 = 100.
84 * @param p1* predicate
85 * @param op logical operator (&&, ||, !)
86 * @param p2* predicate
87 */
88 void setTerm(Predicate *p1, LogicalOp op, Predicate *p2 = NULL);
92 /**
93 * @class Predicate
95 * @brief Represents a single term in the condition.
96 * Condition is logical expression composed of terms and logical operators. This
97 * represents the leaf of the logical expression tree. This is designed using composite
98 * design pattern
102 class Predicate
104 public:
105 virtual void setTerm(const char* fName1, ComparisionOp op, const char *fName2)=0;
107 //Operand should be of the same type of the field. This is must
108 virtual void setTerm(const char* fName1, ComparisionOp op, void *opnd)=0;
110 //Operand should be of the same type of the field. This is must
111 virtual void setTerm(const char* fName1, ComparisionOp op, void **opnd)=0;
113 virtual void setTerm(Predicate *p1, LogicalOp op, Predicate *p2 = NULL)=0;
115 virtual void print()=0;
116 virtual ~Predicate(){}
120 #endif