Its made sure that all the cases present in sqlapi/Connect worked for network
[csql.git] / include / TableImpl.h
blob415e233cba3d34ebf74591a5ed673b90a9e47b53
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 TreeIter *tIter;
45 IndexInfo *info;
46 void *chunkPtr_;
47 int procSlot;
49 TupleIterator(){}
50 public:
52 TupleIterator(Predicate *p, ScanType t, IndexInfo *i, void *cptr, int pslot)
53 { bIter = NULL; pred_ = p ; scanType_ = t; info = i; chunkPtr_ = cptr; procSlot =pslot;}
55 ~TupleIterator()
57 if (bIter) delete bIter;
58 bIter = NULL;
61 DbRetVal open();
62 void* next();
63 void* prev();//used only for tree iter during deleteTuple
64 DbRetVal close();
67 class TableImpl:public Table
69 private:
72 LockManager *lMgr_;
73 Transaction **trans;
74 //This is pointer to the pointer stored in the
75 //Transaction manager.
76 //If the transaction commits/aborts this pointer changes
77 //and this will get that newly allocated transaction
79 char tblName_[IDENTIFIER_LENGTH];
80 int tblID_;
81 size_t length_; //length of the tuple
82 int numFlds_;
83 void* chunkPtr_;
84 void *curTuple_; //holds the current tuple ptr. moved during fetch() calls
86 Predicate *pred_;
87 ScanType scanType_;
88 //ChunkIterator *iter;
89 //BucketIter *bIter;
91 TupleIterator *iter;
93 bool undoFlag;
95 public:
96 FieldList fldList_;
97 int numIndexes_;
98 char** indexPtr_; // array of index ptrs to the catalog table for the indexes of this table.
99 IndexInfo **idxInfo;
100 int useIndex_;//offet in the above array indexPtr_ for scan
101 bool isPlanCreated;
103 Database *db_;
104 Database *sysDB_;
106 //Either one of the below is populated based on the no of fields and
107 //is used for tuple insertions
108 bool isIntUsedForNULL;
109 int iNullInfo;
110 char *cNullInfo;
111 int iNotNullInfo;
112 char *cNotNullInfo;
114 private:
116 //copy Values from binded buffer to tuple pointed by arg
117 DbRetVal copyValuesFromBindBuffer(void *tuple, bool isInsert=true);
118 DbRetVal copyValuesToBindBuffer(void *tuple);
119 void setNullBit(int fldpos);
120 void clearNullBit(int fldpos);
121 DbRetVal insertIndexNode(Transaction *trans, void *indexPtr, IndexInfo *info, void *tuple);
122 DbRetVal updateIndexNode(Transaction *trans, void *indexPtr, IndexInfo *info, void *tuple);
123 DbRetVal deleteIndexNode(Transaction *trans, void *indexPtr, IndexInfo *info, void *tuple);
125 DbRetVal createPlan();
126 Chunk* getSystemTableChunk(CatalogTableID id)
128 return sysDB_->getSystemDatabaseChunk(id);
131 public:
132 TableImpl() { db_ = NULL; chunkPtr_ = NULL; iter = NULL;
133 idxInfo = NULL; indexPtr_ = NULL; scanType_ = unknownScan;
134 pred_ = NULL; useIndex_ = -1; numFlds_ = 0;
135 iNullInfo = 0; cNullInfo = NULL; isIntUsedForNULL = true;
136 iNotNullInfo = 0; cNotNullInfo = NULL;
137 isPlanCreated = false; undoFlag = true;}
138 ~TableImpl();
140 void setDB(Database *db) { db_ = db; }
141 Database* getDB() { return db_;}
142 void setSystemDB(Database *db) { sysDB_ = db; }
143 void setLockManager(LockManager *lmgr) { lMgr_ = lmgr; }
144 void setTrans(Transaction **t) { trans = t; }
146 DataType getFieldType(const char *name)
147 { return fldList_.getFieldType(name); }
148 int getFieldOffset(const char *name)
149 { return fldList_.getFieldOffset(name); }
150 size_t getFieldLength(const char *name)
151 { return fldList_.getFieldLength(name); }
153 DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info)
155 char tblName[IDENTIFIER_LENGTH];
156 char fldName[IDENTIFIER_LENGTH];
157 getTableNameAlone((char*)fieldName, tblName);
158 getFieldNameAlone((char*)fieldName, fldName);
159 if (0 == strcmp(tblName, "") || 0 ==strcmp(tblName, getName()))
160 return fldList_.getFieldInfo(fldName, info);
161 else
162 return ErrNotExists;
165 List getFieldNameList();
167 // search predicate
168 void setCondition(Condition *p)
169 { isPlanCreated = false; if (p) pred_ = p->getPredicate(); else pred_ = NULL;}
171 //binding
172 DbRetVal bindFld(const char *name, void *val);
173 void *getBindFldAddr(const char *name);
175 void markFldNull(const char *name);
176 void markFldNull(int colpos);
177 bool isFldNull(const char *name);
178 bool isFldNull(int colpos);
180 void clearFldNull(const char *name);
181 void clearFldNull(int colpos);
182 void resetNullinfo();
184 DbRetVal insertTuple();
185 DbRetVal updateTuple();
187 DbRetVal deleteTuple();
188 int deleteWhere();
189 int truncate();
191 DbRetVal execute();
193 void* fetch();
194 void* fetch(DbRetVal &rv);
195 void* fetchNoBind();
196 void* fetchNoBind(DbRetVal &rv);
198 DbRetVal close();
201 long spaceUsed();
202 long numTuples();
203 int pagesUsed();
204 void printInfo();
206 DbRetVal lock(bool shared);
207 DbRetVal unlock();
209 DbRetVal setUndoLogging(bool flag) { undoFlag = flag; }
211 void printSQLIndexString();
212 char* getName() { return tblName_; }
213 void setTableInfo(char *name, int tblid, size_t length,
214 int numFld, int numIdx, void *chunk);
215 friend class DatabaseManagerImpl;
219 #endif