using tree index
[csql.git] / include / AggTableImpl.h
blobb88ec54bdf7f909669d1e76aa224cbef64412a17
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 void *getBindFldAddr(const char *name);
86 DbRetVal bindFld(const char *name, void *val);
87 DbRetVal bindFld(const char *name, AggType aggType, void *val);
88 DbRetVal setGroup(const char *name, void *val);
89 void setCondition(Condition *p){}
90 void markFldNull(const char *name){}
91 void markFldNull(int colpos){}
92 bool isFldNull(const char *name){return false;}
93 bool isFldNull(int colpos){return false;}
94 void clearFldNull(const char *name){}
95 void clearFldNull(int colpos){}
96 DbRetVal insertTuple() { return ErrBadCall; }
97 DbRetVal updateTuple() { return ErrBadCall; }
98 DbRetVal deleteTuple() { return ErrBadCall; }
99 int deleteWhere() { return ErrBadCall; }
100 int truncate() { return ErrBadCall; }
101 long spaceUsed() { return 0; }
102 int pagesUsed() { return 0; }
103 DbRetVal lock(bool shared) { return ErrBadCall; }
104 DbRetVal unlock(){ return ErrBadCall; }
105 DbRetVal setUndoLogging(bool flag) { return ErrBadCall; }
106 void printSQLIndexString(){ };
107 char* getName() { return tableHdl->getName(); }
108 List getFieldNameList(){ List list; return list;}
109 DbRetVal execute();
110 void* fetch();
111 void* fetch(DbRetVal &rv);
112 void* fetchNoBind();
113 void* fetchNoBind(DbRetVal &rv);
114 DbRetVal close();
115 long numTuples();
116 void printInfo();
124 enum JoinType
126 INNER_JOIN = 1,
127 RIGHT_JOIN,
128 LEFT_JOIN,
129 FULL_JOIN,
130 UNKNOWN_JOIN
132 class JoinProjFieldInfo
134 public:
135 char tableName[IDENTIFIER_LENGTH];
136 char fieldName[IDENTIFIER_LENGTH];
137 DataType type;
138 int length;
139 void *appBuf;
140 void *bindBuf;
141 JoinProjFieldInfo()
143 strcpy(tableName,""); strcpy(fieldName, "");
144 type= typeUnknown; length =0; appBuf= NULL; bindBuf=NULL;
147 class JoinCondition
149 public:
150 char tableName1[IDENTIFIER_LENGTH];
151 char tableName2[IDENTIFIER_LENGTH];
152 char fieldName1[IDENTIFIER_LENGTH];
153 char fieldName2[IDENTIFIER_LENGTH];
154 DataType type1;
155 DataType type2;
156 int length1;
157 int length2;
158 void *bindBuf1;
159 void *bindBuf2;
160 bool alreadyBinded1;
161 bool alreadyBinded2;
162 ComparisionOp op;
163 JoinCondition()
165 strcpy(tableName1,""); strcpy(fieldName1, "");
166 strcpy(tableName2,""); strcpy(fieldName2, "");
167 type1= typeUnknown; length1 =0; bindBuf1=NULL;
168 type2= typeUnknown; length2 =0; bindBuf2=NULL;
169 alreadyBinded1=false; alreadyBinded2=false;
173 class JoinTableImpl:public Table
175 private:
176 void *curTuple; //holds the current tuple ptr. moved during fetch() calls
177 List projList;
178 Table *leftTableHdl;
179 Table *rightTableHdl;
181 JoinType jType;
182 ListIterator rsIter;
183 bool isNestedLoop;
184 bool rightExhausted;
185 DbRetVal copyValuesToBindBuffer(void *tuple);
186 JoinCondition jCondition;
188 public:
189 JoinTableImpl();
190 virtual ~JoinTableImpl();
192 DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info)
193 { return ErrBadCall; }
195 void setTable(Table *left, Table *right)
196 { leftTableHdl = left; rightTableHdl = right; }
198 void closeScan();
199 void setJoinType(JoinType type) { jType = type; }
200 //binding
201 DbRetVal bindFld(const char *name, void *val);
202 DbRetVal setJoinCondition(const char *fldname1, ComparisionOp op,
203 const char *fldname2);
204 void getFieldNameAlone(char*, char*);
205 void getTableNameAlone(char*, char*);
207 void setCondition(Condition *p){}
208 void markFldNull(const char *name){}
209 void markFldNull(int colpos){}
210 bool isFldNull(const char *name){return false;}
211 bool isFldNull(int colpos){return false;}
212 void clearFldNull(const char *name){}
213 void clearFldNull(int colpos){}
214 DbRetVal insertTuple() { return ErrBadCall; }
215 DbRetVal updateTuple() { return ErrBadCall; }
216 DbRetVal deleteTuple() { return ErrBadCall; }
217 int deleteWhere() { return ErrBadCall; }
218 int truncate() { return ErrBadCall; }
219 long spaceUsed() { return 0; }
220 int pagesUsed() { return 0; }
221 DbRetVal lock(bool shared) { return ErrBadCall; }
222 DbRetVal unlock(){ return ErrBadCall; }
223 DbRetVal setUndoLogging(bool flag) { return ErrBadCall; }
224 void printSQLIndexString(){ };
225 List getFieldNameList(){ List list; return list;}
226 char* getName() { return NULL; }
228 bool evaluate();
229 DbRetVal execute();
230 void* fetch();
231 void* fetch(DbRetVal &rv);
232 void* fetchNoBind();
233 void* fetchNoBind(DbRetVal &rv);
234 DbRetVal close();
236 long numTuples();
237 void printInfo();
242 #endif