windows changes
[csql.git] / include / JoinTableImpl.h
blob27bd61c1e0fce1e7c2c3ac09f0a4bf39c04906b5
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>
29 #ifndef JOINTYPE
30 #define JOINTYPE
31 enum JoinType
33 INNER_JOIN = 1,
34 LEFT_JOIN,
35 RIGHT_JOIN,
36 FULL_JOIN,
37 UNKNOWN_JOIN
39 #endif
41 class DllExport JoinProjFieldInfo
43 public:
44 char tabFieldName[IDENTIFIER_LENGTH*2];
45 char tableName[IDENTIFIER_LENGTH];
46 char fieldName[IDENTIFIER_LENGTH];
47 DataType type;
48 int length;
49 void *appBuf;
50 void *bindBuf;
51 JoinProjFieldInfo()
53 strcpy(tableName,""); strcpy(fieldName, "");
54 type= typeUnknown; length =0; appBuf= NULL; bindBuf=NULL;
57 class DllExport JoinCondition
59 public:
60 char tableName1[IDENTIFIER_LENGTH];
61 char tableName2[IDENTIFIER_LENGTH];
62 char fieldName1[IDENTIFIER_LENGTH];
63 char fieldName2[IDENTIFIER_LENGTH];
64 DataType type1;
65 DataType type2;
66 int length1;
67 int length2;
68 void *bindBuf1;
69 void *bindBuf2;
70 bool alreadyBinded1;
71 bool alreadyBinded2;
72 ComparisionOp op;
73 JoinCondition()
75 strcpy(tableName1,""); strcpy(fieldName1, "");
76 strcpy(tableName2,""); strcpy(fieldName2, "");
77 type1= typeUnknown; length1 =0; bindBuf1=NULL;
78 type2= typeUnknown; length2 =0; bindBuf2=NULL;
79 alreadyBinded1=false; alreadyBinded2=false;
83 class DllExport JoinTableImpl:public Table
85 private:
86 void *curTuple; //holds the current tuple ptr. moved during fetch() calls
87 List projList;
88 Table *leftTableHdl;
89 Table *rightTableHdl;
90 bool availableLeft;
91 bool isFirstFetch;
92 bool isReturnNull;
93 //bool isOuterJoin;
94 bool isOptimized;
95 bool isLeftRecOver;
96 bool isFirstCall;
97 bool leftSideFail;
99 JoinType jType;
100 ListIterator rsIter;
101 bool isNestedLoop;
102 bool rightExhausted;
103 DbRetVal copyValuesToBindBuffer(void *tuple);
104 JoinCondition jCondition;
105 Predicate *pred;
106 List predList;
108 public:
109 JoinTableImpl();
110 virtual ~JoinTableImpl();
112 DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info);
114 void setTable(Table *left, Table *right)
115 { leftTableHdl = left; rightTableHdl = right; }
116 int getFldPos(char *name){ return 0;}
117 DbRetVal closeScan();
118 void setJoinType(JoinType type) { jType = type; }
119 //binding
120 DbRetVal bindFld(const char *name, void *val, bool dummy=false);
121 //DbRetVal setJoinCondition(const char *fldname1, ComparisionOp op,
122 // const char *fldname2);
124 void setCondition(Condition *p)
125 { if (p) pred = p->getPredicate(); else pred = NULL;}
127 DbRetVal markFldNull(const char *name){ return ErrBadCall;}
128 DbRetVal markFldNull(int colpos){ return ErrBadCall;}
129 bool isFldNull(const char *name);
130 bool isFldNullInt(const char *name);
131 bool isFldNull(int colpos){return false;}
132 void clearFldNull(const char *name){}
133 void clearFldNull(int colpos){}
134 void resetNullinfo(){ }
135 DbRetVal insertTuple() { return ErrBadCall; }
136 DbRetVal updateTuple() { return ErrBadCall; }
137 DbRetVal deleteTuple() { return ErrBadCall; }
138 int deleteWhere() { return ErrBadCall; }
139 int truncate() { return ErrBadCall; }
140 long spaceUsed() { return 0; }
141 int pagesUsed() { return 0; }
142 DbRetVal lock(bool shared) { return ErrBadCall; }
143 DbRetVal unlock(){ return ErrBadCall; }
144 DbRetVal setUndoLogging(bool flag) { return ErrBadCall; }
145 void printSQLIndexString(FILE *fp, int fd){ };
146 void printSQLForeignString(){}
147 List getFieldNameList();
148 char* getName() { return NULL; }
149 char* getAliasName(){ return NULL; }
150 void *fetchRightFail();
151 DbRetVal compact(){ return OK;}
152 //bool evaluate();
153 DbRetVal execute();
154 void* fetch();
155 void* fetchInt();
156 void* fetch(DbRetVal &rv);
157 void* fetchNoBind();
158 void* fetchNoBind(DbRetVal &rv);
159 DbRetVal close();
161 long numTuples();
162 void printInfo();
163 void *getBindFldAddr(const char *name);
164 bool isFKTable(){return false;}
165 bool isTableInvolved(char *tblName);
166 bool pushPredicate(Predicate *pred);
167 void setPredicate(Predicate *pred);
168 void printPlan(int space);
169 DbRetVal optimize();
170 void optimizeRestrict();
171 ScanType getScanType();
172 bool hasIndex(char *fname){ return false; }
173 void* getBindedBuf(char* tName, char*fName);
177 #endif