Removing large file for data load. Modified README to generate mysql and psql input...
[csql.git] / include / TableImpl.h
blob4d8bd7b544fc8a3d66234c87a3de8767e4254405
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 TABLE_IMPL_H
17 #define TABLE_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 ScanType
30 fullTableScan = 0,
31 hashIndexScan,
32 treeIndexScan,
33 unknownScan
36 static char ScanTypeNames[][10] =
38 "TableScan", "HashScan", "TreeScan", "Invalid"
41 class Predicate;
43 class TupleIterator
45 Predicate *pred_;
46 ScanType scanType_;
47 ChunkIterator *cIter;
48 BucketIter *bIter;
49 TreeIter *tIter;
50 IndexInfo *info;
51 void *chunkPtr_;
52 int procSlot;
53 bool isBetween;
54 bool isPointLook;
56 TupleIterator(){}
57 public:
58 TupleIterator(Predicate *p, ScanType t, IndexInfo *i, void *cptr, int pslot,bool between , bool isPtLook)
59 { bIter = NULL; pred_ = p ; scanType_ = t; info = i; chunkPtr_ = cptr; procSlot =pslot; isBetween=between; isPointLook=isPtLook; }
61 ~TupleIterator()
63 if (bIter) delete bIter;
64 bIter = NULL;
66 bool isBetInvolved(){ return isBetween;}
67 void setBetInvolved(bool between){ isBetween=between;}
68 bool isPointLookInvolved(){return isPointLook;}
69 DbRetVal open();
70 void* next();
71 void* prev();//used only for tree iter during deleteTuple
72 DbRetVal close();
75 class TableImpl:public Table
77 private:
80 LockManager *lMgr_;
81 Transaction **trans;
82 //This is pointer to the pointer stored in the
83 //Transaction manager.
84 //If the transaction commits/aborts this pointer changes
85 //and this will get that newly allocated transaction
87 char tblName_[IDENTIFIER_LENGTH];
88 int tblID_;
89 size_t length_; //length of the tuple
90 int numFlds_;
91 void* chunkPtr_;
92 void *curTuple_; //holds the current tuple ptr. moved during fetch() calls
94 Predicate *pred_;
95 ScanType scanType_;
96 //ChunkIterator *iter;
97 //BucketIter *bIter;
99 TupleIterator *iter;
101 bool undoFlag;
103 public:
104 FieldList fldList_;
105 int numIndexes_;
106 char** indexPtr_; // array of index ptrs to the catalog table for the indexes of this table.
107 IndexInfo **idxInfo;
108 int useIndex_;//offet in the above array indexPtr_ for scan
109 bool isPlanCreated;
110 bool isPointLook;
111 bool isBetween;
112 Database *db_;
113 Database *sysDB_;
115 //Either one of the below is populated based on the no of fields and
116 //is used for tuple insertions
117 bool isIntUsedForNULL;
118 int iNullInfo;
119 char *cNullInfo;
120 int iNotNullInfo;
121 char *cNotNullInfo;
123 private:
125 //copy Values from binded buffer to tuple pointed by arg
126 DbRetVal copyValuesFromBindBuffer(void *tuple, bool isInsert=true);
127 DbRetVal copyValuesToBindBuffer(void *tuple);
128 void setNullBit(int fldpos);
129 void clearNullBit(int fldpos);
130 DbRetVal insertIndexNode(Transaction *trans, void *indexPtr, IndexInfo *info, void *tuple);
131 DbRetVal updateIndexNode(Transaction *trans, void *indexPtr, IndexInfo *info, void *tuple);
132 DbRetVal deleteIndexNode(Transaction *trans, void *indexPtr, IndexInfo *info, void *tuple);
134 DbRetVal createPlan();
135 Chunk* getSystemTableChunk(CatalogTableID id)
137 return sysDB_->getSystemDatabaseChunk(id);
140 public:
141 TableImpl() { db_ = NULL; chunkPtr_ = NULL; iter = NULL;
142 idxInfo = NULL; indexPtr_ = NULL; scanType_ = unknownScan;
143 pred_ = NULL; useIndex_ = -1; numFlds_ = 0;
144 iNullInfo = 0; cNullInfo = NULL; isIntUsedForNULL = true;
145 iNotNullInfo = 0; cNotNullInfo = NULL; curTuple_ = NULL;
146 isPlanCreated = false; undoFlag = true;}
147 ~TableImpl();
149 void setDB(Database *db) { db_ = db; }
150 Database* getDB() { return db_;}
151 void setSystemDB(Database *db) { sysDB_ = db; }
152 void setLockManager(LockManager *lmgr) { lMgr_ = lmgr; }
153 void setTrans(Transaction **t) { trans = t; }
154 void setCurTuple(void *tuple){ curTuple_=tuple; }
155 DataType getFieldType(const char *name)
156 { return fldList_.getFieldType(name); }
157 int getFieldOffset(const char *name)
158 { return fldList_.getFieldOffset(name); }
159 size_t getFieldLength(const char *name)
160 { return fldList_.getFieldLength(name); }
162 DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info)
164 char tblName[IDENTIFIER_LENGTH];
165 char fldName[IDENTIFIER_LENGTH];
166 getTableNameAlone((char*)fieldName, tblName);
167 getFieldNameAlone((char*)fieldName, fldName);
168 if (0 == strcmp(tblName, "") || 0 ==strcmp(tblName, getName()))
169 return fldList_.getFieldInfo(fldName, info);
170 else
171 return ErrNotExists;
174 List getFieldNameList();
176 // search predicate
177 void setCondition(Condition *p)
178 { isPlanCreated = false; if (p) pred_ = p->getPredicate(); else pred_ = NULL;}
180 //binding
181 DbRetVal bindFld(const char *name, void *val);
182 void *getBindFldAddr(const char *name);
183 int getFldPos(char *name);
184 DbRetVal markFldNull(const char *name);
185 DbRetVal markFldNull(int colpos);
186 bool isFldNull(const char *name);
187 bool isFldNull(int colpos);
189 void clearFldNull(const char *name);
190 void clearFldNull(int colpos);
191 void resetNullinfo();
192 DbRetVal insertTuple();
193 DbRetVal updateTuple();
195 DbRetVal deleteTuple();
196 int deleteWhere();
197 int truncate();
199 DbRetVal execute();
201 void* fetch();
202 void* fetch(DbRetVal &rv);
203 void* fetchNoBind();
204 void* fetchNoBind(DbRetVal &rv);
206 DbRetVal close();
207 DbRetVal closeScan();
210 long spaceUsed();
211 long numTuples();
212 int pagesUsed();
213 void printInfo();
214 void printPlan(int space);
216 DbRetVal lock(bool shared);
217 DbRetVal unlock();
219 DbRetVal setUndoLogging(bool flag) { undoFlag = flag; }
221 void printSQLIndexString();
222 bool isTableInvolved(char *tblName);
223 bool pushPredicate(Predicate *pred);
224 void setPredicate(Predicate *pred);
225 char* getName() { return tblName_; }
226 void setTableInfo(char *name, int tblid, size_t length,
227 int numFld, int numIdx, void *chunk);
228 friend class DatabaseManagerImpl;
232 #endif