changing file creation mode from 777 to 644
[csql.git] / include / Predicate.h
blob38fd742580eaac80d7393dff313b359b9d530512
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 #ifndef AGGTYPE
23 enum AggType
25 AGG_MIN = 1,
26 AGG_MAX,
27 AGG_SUM,
28 AGG_AVG,
29 AGG_COUNT,
30 AGG_UNKNOWN
32 #define AGGTYPE
33 #endif
36 /**
37 * @class Condition
39 * @brief Represents the condition part of SQL Query.
40 * Used in SELECT, UPDATE and DELETE statement to retrieve only tuples which satisfy<br/>
41 * the condition. This represents the root of the logical expression. This logical <br/>
42 * expression may contain multiple terms(predicates).<br/>
43 * For example to set this condition f1 == f2 && f1 == 100. <br/>
44 * Condition c1;<br/>
45 * int val1 = 100;<br/>
46 * c1.setTerm("f1", OpEquals, &val1);<br/>
47 * Predicate *p1 = c1.getPredicate();<br/>
48 * Condition c2;<br/>
49 * c2.setTerm("f1", opEquals, "f2");<br/>
50 * Predicate *p2 = c2.getPredicate();<br/>
51 * Condtion rootCondition;<br/>
52 * rootCondition.setTerm(p1, OpAnd, p2);<br/>
53 * table->setCondition(rootCondition);<br/>
56 class Condition
58 Predicate *pred;
59 public:
60 Condition();
61 ~Condition();
62 void reset();
64 /** gets the current predicate. This is used to create logical expressions with terms or predicates.
65 * @return Predicate* predicate
66 */
67 Predicate* getPredicate() { return pred; }
69 /** sets the current predicate. This is set after creating the logical expression and used in the table interface for setting the condition.
70 * @param Predicate* predicate
71 */
72 void setPredicate(Predicate * predicate) { pred = predicate; }
75 /** sets the predicate term of form f1 = f2.
76 * @param fName1* field name
77 * @param op comparision operator
78 * @param fName2* field name
79 */
80 void setTerm(const char* fName1, ComparisionOp op, const char *fName2);
82 /** sets the predicate term of form f1 = 10
83 * @param fName1* field name
84 * @param op comparision operator(=,!=, >,<,>=,<=)
85 * @param opnd* pointer to the value
86 */
87 void setTerm(const char* fName1, ComparisionOp op, void *opnd);
89 /** sets the predicate term of form f1 =10, using pointer semantics
90 * @param fName1* field name
91 * @param op comparision operator(=,!=, >,<,>=,<=)
92 * @param opnd** pointer to pointer to the value
93 */
94 void setTerm(const char* fName1, ComparisionOp op, void **opnd );
95 void setTerm(const char* fName1, ComparisionOp op, void **opnd, AggType aggType);
98 /** sets the predicate term of form f1 = f2 && f1 = 100.
99 * @param p1* predicate
100 * @param op logical operator (&&, ||, !)
101 * @param p2* predicate
103 void setTerm(Predicate *p1, LogicalOp op, Predicate *p2 = NULL);
108 * @class Predicate
110 * @brief Represents a single term in the condition.
111 * Condition is logical expression composed of terms and logical operators. This
112 * represents the leaf of the logical expression tree. This is designed using composite
113 * design pattern
117 class Predicate
119 public:
120 virtual void setTerm(const char* fName1, ComparisionOp op, const char *fName2)=0;
122 //Operand should be of the same type of the field. This is must
123 virtual void setTerm(const char* fName1, ComparisionOp op, void *opnd)=0;
125 //Operand should be of the same type of the field. This is must
126 virtual void setTerm(const char* fName1, ComparisionOp op, void **opnd)=0;
128 virtual void setTerm(Predicate *p1, LogicalOp op, Predicate *p2 = NULL)=0;
129 virtual void setTerm(const char* fName1, ComparisionOp op,bool nullFlag)=0;
130 virtual void print(int space)=0;
131 virtual ~Predicate(){}
135 #endif