Adding test framework and some sample test modules and test cases to the sytem.
[csql.git] / include / Predicate.h
blobb30ced569ac9a807ed14b2225c7a7693be66a4e3
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/>
40 * @author Prabakaran Thirumalai
42 class Condition
44 Predicate *pred;
45 public:
46 Condition();
47 ~Condition();
49 /** gets the current predicate. This is used to create logical expressions with terms or predicates.
50 * @return Predicate* predicate
51 */
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
57 */
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
64 */
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
71 */
72 void setTerm(Predicate *p1, LogicalOp op, Predicate *p2 = NULL);
76 /**
77 * @class Predicate
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
82 * design pattern
84 * @author Prabakaran Thirumalai
86 class Predicate
88 public:
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(){}
99 #endif