changes for join table and parser for aggregates
[csql.git] / include / AggTableImpl.h
blob4d02fbe5eae43ed7bfe0a3965171624272f9cf74
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #ifndef JOINTABLE_IMPL_H
17 #define JOINTABLE_IMPL_H
18 #include<os.h>
19 #include<DataType.h>
20 #include<Transaction.h>
21 #include<Database.h>
22 #include<Index.h>
23 #include<CatalogTables.h>
24 #include<Info.h>
25 #include<Debug.h>
26 #include<DatabaseManagerImpl.h>
27 #include<Predicate.h>
28 enum AggType
30 AGG_MIN = 1,
31 AGG_MAX,
32 AGG_SUM,
33 AGG_AVG,
34 AGG_COUNT,
35 AGG_UNKNOWN
37 class AggFldDef
39 public:
40 char fldName[IDENTIFIER_LENGTH];
41 DataType type;
42 int length;
43 void *bindBuf;
44 void *appBuf;
45 AggType atype;
46 bool alreadyBinded;
47 AggFldDef()
49 strcpy(fldName, "");
50 type=typeUnknown;
51 length=0;
52 bindBuf=NULL;
53 appBuf=NULL;
54 atype=AGG_UNKNOWN;
55 alreadyBinded=false;
59 class AggTableImpl:public Table
61 private:
62 char tblName_[IDENTIFIER_LENGTH];
63 void *curTuple; //holds the current tuple ptr. moved during fetch() calls
64 List fldList;
65 AggFldDef groupFld;
66 Table *tableHdl;
67 List aggNodes; //change this list to some other data structure
68 ListIterator aggNodeIter;
70 int aggNodeSize;
71 DbRetVal copyValuesToBindBuffer(void *tuple);
72 public:
73 AggTableImpl();
74 virtual ~AggTableImpl();
75 DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info)
76 { return ErrBadCall; }
77 bool isGroupSet()
79 if (groupFld.type == typeUnknown) return false; else return true;
81 void* insertOrGet();
82 void setTable(Table *impl){ tableHdl = impl;}
83 Table* getTableHdl(){ return tableHdl; }
84 void closeScan();
85 DbRetVal bindFld(const char *name, void *val);
86 DbRetVal bindFld(const char *name, AggType aggType, void *val);
87 DbRetVal setGroup(const char *name, void *val);
88 void setCondition(Condition *p){}
89 void markFldNull(const char *name){}
90 void markFldNull(int colpos){}
91 bool isFldNull(const char *name){return false;}
92 bool isFldNull(int colpos){return false;}
93 void clearFldNull(const char *name){}
94 void clearFldNull(int colpos){}
95 DbRetVal insertTuple() { return ErrBadCall; }
96 DbRetVal updateTuple() { return ErrBadCall; }
97 DbRetVal deleteTuple() { return ErrBadCall; }
98 int deleteWhere() { return ErrBadCall; }
99 int truncate() { return ErrBadCall; }
100 long spaceUsed() { return 0; }
101 int pagesUsed() { return 0; }
102 DbRetVal lock(bool shared) { return ErrBadCall; }
103 DbRetVal unlock(){ return ErrBadCall; }
104 DbRetVal setUndoLogging(bool flag) { return ErrBadCall; }
105 void printSQLIndexString(){ };
106 char* getName() { return tableHdl->getName(); }
107 List getFieldNameList(){ List list; return list;}
108 DbRetVal execute();
109 void* fetch();
110 void* fetch(DbRetVal &rv);
111 void* fetchNoBind();
112 void* fetchNoBind(DbRetVal &rv);
113 DbRetVal close();
114 long numTuples();
115 void printInfo();
123 enum JoinType
125 INNER_JOIN = 1,
126 RIGHT_JOIN,
127 LEFT_JOIN,
128 FULL_JOIN,
129 UNKNOWN_JOIN
131 class JoinProjFieldInfo
133 public:
134 char tableName[IDENTIFIER_LENGTH];
135 char fieldName[IDENTIFIER_LENGTH];
136 DataType type;
137 int length;
138 void *appBuf;
139 void *bindBuf;
140 JoinProjFieldInfo()
142 strcpy(tableName,""); strcpy(fieldName, "");
143 type= typeUnknown; length =0; appBuf= NULL; bindBuf=NULL;
146 class JoinCondition
148 public:
149 char tableName1[IDENTIFIER_LENGTH];
150 char tableName2[IDENTIFIER_LENGTH];
151 char fieldName1[IDENTIFIER_LENGTH];
152 char fieldName2[IDENTIFIER_LENGTH];
153 DataType type1;
154 DataType type2;
155 int length1;
156 int length2;
157 void *bindBuf1;
158 void *bindBuf2;
159 bool alreadyBinded1;
160 bool alreadyBinded2;
161 ComparisionOp op;
162 JoinCondition()
164 strcpy(tableName1,""); strcpy(fieldName1, "");
165 strcpy(tableName2,""); strcpy(fieldName2, "");
166 type1= typeUnknown; length1 =0; bindBuf1=NULL;
167 type2= typeUnknown; length2 =0; bindBuf2=NULL;
168 alreadyBinded1=false; alreadyBinded2=false;
172 class JoinTableImpl:public Table
174 private:
175 void *curTuple; //holds the current tuple ptr. moved during fetch() calls
176 List projList;
177 Table *leftTableHdl;
178 Table *rightTableHdl;
180 JoinType jType;
181 ListIterator rsIter;
182 bool isNestedLoop;
183 bool rightExhausted;
184 DbRetVal copyValuesToBindBuffer(void *tuple);
185 JoinCondition jCondition;
187 public:
188 JoinTableImpl();
189 virtual ~JoinTableImpl();
191 DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info)
192 { return ErrBadCall; }
194 void setTable(Table *left, Table *right)
195 { leftTableHdl = left; rightTableHdl = right; }
197 void closeScan();
198 void setJoinType(JoinType type) { jType = type; }
199 //binding
200 DbRetVal bindFld(const char *name, void *val);
201 DbRetVal setJoinCondition(const char *fldname1, ComparisionOp op,
202 const char *fldname2);
203 void getFieldNameAlone(char*, char*);
204 void getTableNameAlone(char*, char*);
206 void setCondition(Condition *p){}
207 void markFldNull(const char *name){}
208 void markFldNull(int colpos){}
209 bool isFldNull(const char *name){return false;}
210 bool isFldNull(int colpos){return false;}
211 void clearFldNull(const char *name){}
212 void clearFldNull(int colpos){}
213 DbRetVal insertTuple() { return ErrBadCall; }
214 DbRetVal updateTuple() { return ErrBadCall; }
215 DbRetVal deleteTuple() { return ErrBadCall; }
216 int deleteWhere() { return ErrBadCall; }
217 int truncate() { return ErrBadCall; }
218 long spaceUsed() { return 0; }
219 int pagesUsed() { return 0; }
220 DbRetVal lock(bool shared) { return ErrBadCall; }
221 DbRetVal unlock(){ return ErrBadCall; }
222 DbRetVal setUndoLogging(bool flag) { return ErrBadCall; }
223 void printSQLIndexString(){ };
224 List getFieldNameList(){ List list; return list;}
225 char* getName() { return NULL; }
227 bool evaluate();
228 DbRetVal execute();
229 void* fetch();
230 void* fetch(DbRetVal &rv);
231 void* fetchNoBind();
232 void* fetchNoBind(DbRetVal &rv);
233 DbRetVal close();
235 long numTuples();
236 void printInfo();
241 #endif