removing unsupported option m in cachetable
[csql.git] / include / TableImpl.h
blob1895f967962530d013c80b03f5ecff6063a62e9e
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 class Predicate;
38 class TupleIterator
40 Predicate *pred_;
41 ScanType scanType_;
42 ChunkIterator *cIter;
43 BucketIter *bIter;
44 IndexInfo *info;
45 void *chunkPtr_;
46 int procSlot;
48 TupleIterator(){}
49 public:
50 TupleIterator(Predicate *p, ScanType t, IndexInfo *i, void *cptr, int pslot)
51 { pred_ = p ; scanType_ = t; info = i; chunkPtr_ = cptr; procSlot =pslot;}
52 DbRetVal open();
53 void* next();
54 DbRetVal close();
57 class TableImpl:public Table
59 private:
62 LockManager *lMgr_;
63 Transaction **trans;
64 //This is pointer to the pointer stored in the
65 //Transaction manager.
66 //If the transaction commits/aborts this pointer changes
67 //and this will get that newly allocated transaction
69 char tblName_[IDENTIFIER_LENGTH];
70 int tblID_;
71 size_t length_; //length of the tuple
72 int numFlds_;
73 void* chunkPtr_;
74 void *curTuple_; //holds the current tuple ptr. moved during fetch() calls
76 Predicate *pred_;
77 ScanType scanType_;
78 //ChunkIterator *iter;
79 //BucketIter *bIter;
81 TupleIterator *iter;
83 bool undoFlag;
85 public:
86 FieldList fldList_;
87 int numIndexes_;
88 char** indexPtr_; // array of index ptrs to the catalog table for the indexes of this table.
89 IndexInfo **idxInfo;
90 int useIndex_;//offet in the above array indexPtr_ for scan
91 bool isPlanCreated;
93 Database *db_;
94 Database *sysDB_;
96 //Either one of the below is populated based on the no of fields and
97 //is used for tuple insertions
98 bool isIntUsedForNULL;
99 int iNullInfo;
100 char *cNullInfo;
101 int iNotNullInfo;
102 char *cNotNullInfo;
104 private:
106 //copy Values from binded buffer to tuple pointed by arg
107 DbRetVal copyValuesFromBindBuffer(void *tuple);
108 DbRetVal copyValuesToBindBuffer(void *tuple);
109 void setNullBit(int fldpos);
111 DbRetVal insertIndexNode(Transaction *trans, void *indexPtr, IndexInfo *info, void *tuple);
112 DbRetVal updateIndexNode(Transaction *trans, void *indexPtr, IndexInfo *info, void *tuple);
113 DbRetVal deleteIndexNode(Transaction *trans, void *indexPtr, IndexInfo *info, void *tuple);
115 DbRetVal createPlan();
116 Chunk* getSystemTableChunk(CatalogTableID id)
118 return sysDB_->getSystemDatabaseChunk(id);
121 public:
122 TableImpl() { db_ = NULL; chunkPtr_ = NULL; iter = NULL;
123 idxInfo = NULL; indexPtr_ = NULL; scanType_ = unknownScan; pred_ = NULL; useIndex_ = -1;
124 iNullInfo = 0; cNullInfo = NULL; isIntUsedForNULL = true;
125 iNotNullInfo = 0; cNotNullInfo = NULL;
126 isPlanCreated = false; undoFlag = true;}
127 ~TableImpl();
129 void setDB(Database *db) { db_ = db; }
130 void setSystemDB(Database *db) { sysDB_ = db; }
131 void setLockManager(LockManager *lmgr) { lMgr_ = lmgr; }
132 void setTrans(Transaction **t) { trans = t; }
134 DataType getFieldType(const char *name)
135 { return fldList_.getFieldType(name); }
136 int getFieldOffset(const char *name)
137 { return fldList_.getFieldOffset(name); }
138 size_t getFieldLength(const char *name)
139 { return fldList_.getFieldLength(name); }
141 DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info)
142 { return fldList_.getFieldInfo(fieldName, info); }
144 List getFieldNameList();
146 // search predicate
147 void setCondition(Condition *p)
148 { isPlanCreated = false; if (p) pred_ = p->getPredicate(); else pred_ = NULL;}
150 //binding
151 DbRetVal bindFld(const char *name, void *val);
153 void markFldNull(const char *name);
154 void markFldNull(int colpos);
155 bool isFldNull(const char *name);
156 bool isFldNull(int colpos);
159 void clearFldNull(const char *name);
160 void clearFldNull(int colpos);
163 DbRetVal insertTuple();
164 DbRetVal updateTuple();
166 DbRetVal deleteTuple();
167 int deleteWhere();
168 int truncate();
170 DbRetVal execute();
172 void* fetch();
173 void* fetch(DbRetVal &rv);
174 void* fetchNoBind();
175 void* fetchNoBind(DbRetVal &rv);
177 DbRetVal close();
180 long spaceUsed();
181 long numTuples();
182 int pagesUsed();
183 void printInfo();
185 DbRetVal lock(bool shared);
186 DbRetVal unlock();
188 DbRetVal setUndoLogging(bool flag) { undoFlag = flag; }
191 void setTableInfo(char *name, int tblid, size_t length,
192 int numFld, int numIdx, void *chunk);
193 friend class DatabaseManagerImpl;
197 #endif