fixing readmes in examples
[csql.git] / include / TableImpl.h
blobc0f5c43ea8f3fd4bc030ea9d4b9e0eca62fc2f76
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:
51 TupleIterator(Predicate *p, ScanType t, IndexInfo *i, void *cptr, int pslot)
52 { bIter = NULL; pred_ = p ; scanType_ = t; info = i; chunkPtr_ = cptr; procSlot =pslot;}
54 ~TupleIterator()
56 if (bIter) delete bIter;
57 bIter = NULL;
60 DbRetVal open();
61 void* next();
62 DbRetVal close();
65 class TableImpl:public Table
67 private:
70 LockManager *lMgr_;
71 Transaction **trans;
72 //This is pointer to the pointer stored in the
73 //Transaction manager.
74 //If the transaction commits/aborts this pointer changes
75 //and this will get that newly allocated transaction
77 char tblName_[IDENTIFIER_LENGTH];
78 int tblID_;
79 size_t length_; //length of the tuple
80 int numFlds_;
81 void* chunkPtr_;
82 void *curTuple_; //holds the current tuple ptr. moved during fetch() calls
84 Predicate *pred_;
85 ScanType scanType_;
86 //ChunkIterator *iter;
87 //BucketIter *bIter;
89 TupleIterator *iter;
91 bool undoFlag;
93 public:
94 FieldList fldList_;
95 int numIndexes_;
96 char** indexPtr_; // array of index ptrs to the catalog table for the indexes of this table.
97 IndexInfo **idxInfo;
98 int useIndex_;//offet in the above array indexPtr_ for scan
99 bool isPlanCreated;
101 Database *db_;
102 Database *sysDB_;
104 //Either one of the below is populated based on the no of fields and
105 //is used for tuple insertions
106 bool isIntUsedForNULL;
107 int iNullInfo;
108 char *cNullInfo;
109 int iNotNullInfo;
110 char *cNotNullInfo;
112 private:
114 //copy Values from binded buffer to tuple pointed by arg
115 DbRetVal copyValuesFromBindBuffer(void *tuple, bool isInsert=true);
116 DbRetVal copyValuesToBindBuffer(void *tuple);
117 void setNullBit(int fldpos);
119 DbRetVal insertIndexNode(Transaction *trans, void *indexPtr, IndexInfo *info, void *tuple);
120 DbRetVal updateIndexNode(Transaction *trans, void *indexPtr, IndexInfo *info, void *tuple);
121 DbRetVal deleteIndexNode(Transaction *trans, void *indexPtr, IndexInfo *info, void *tuple);
123 DbRetVal createPlan();
124 Chunk* getSystemTableChunk(CatalogTableID id)
126 return sysDB_->getSystemDatabaseChunk(id);
129 public:
130 TableImpl() { db_ = NULL; chunkPtr_ = NULL; iter = NULL;
131 idxInfo = NULL; indexPtr_ = NULL; scanType_ = unknownScan;
132 pred_ = NULL; useIndex_ = -1; numFlds_ = 0;
133 iNullInfo = 0; cNullInfo = NULL; isIntUsedForNULL = true;
134 iNotNullInfo = 0; cNotNullInfo = NULL;
135 isPlanCreated = false; undoFlag = true;}
136 ~TableImpl();
138 void setDB(Database *db) { db_ = db; }
139 void setSystemDB(Database *db) { sysDB_ = db; }
140 void setLockManager(LockManager *lmgr) { lMgr_ = lmgr; }
141 void setTrans(Transaction **t) { trans = t; }
143 DataType getFieldType(const char *name)
144 { return fldList_.getFieldType(name); }
145 int getFieldOffset(const char *name)
146 { return fldList_.getFieldOffset(name); }
147 size_t getFieldLength(const char *name)
148 { return fldList_.getFieldLength(name); }
150 DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info)
151 { return fldList_.getFieldInfo(fieldName, info); }
153 List getFieldNameList();
155 // search predicate
156 void setCondition(Condition *p)
157 { isPlanCreated = false; if (p) pred_ = p->getPredicate(); else pred_ = NULL;}
159 //binding
160 DbRetVal bindFld(const char *name, void *val);
162 void markFldNull(const char *name);
163 void markFldNull(int colpos);
164 bool isFldNull(const char *name);
165 bool isFldNull(int colpos);
168 void clearFldNull(const char *name);
169 void clearFldNull(int colpos);
172 DbRetVal insertTuple();
173 DbRetVal updateTuple();
175 DbRetVal deleteTuple();
176 int deleteWhere();
177 int truncate();
179 DbRetVal execute();
181 void* fetch();
182 void* fetch(DbRetVal &rv);
183 void* fetchNoBind();
184 void* fetchNoBind(DbRetVal &rv);
186 DbRetVal close();
189 long spaceUsed();
190 long numTuples();
191 int pagesUsed();
192 void printInfo();
194 DbRetVal lock(bool shared);
195 DbRetVal unlock();
197 DbRetVal setUndoLogging(bool flag) { undoFlag = flag; }
199 void printSQLIndexString();
200 char* getName() { return tblName_; }
201 void setTableInfo(char *name, int tblid, size_t length,
202 int numFld, int numIdx, void *chunk);
203 friend class DatabaseManagerImpl;
207 #endif