Initial revision
[csql.git] / include / TableImpl.h
blobceefc73a47221346e56eecbb416d2142d21d995e
1 /***************************************************************************
2 * Copyright (C) 2007 by Prabakaran Thirumalai *
3 * praba_tuty@yahoo.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_;
47 TupleIterator(){}
48 public:
49 TupleIterator(Predicate *p, ScanType t, IndexInfo *i, void *cptr)
50 { pred_ = p ; scanType_ = t; info = i; chunkPtr_ = cptr; }
51 DbRetVal open();
52 void* next();
53 DbRetVal close();
56 class TableImpl:public Table
58 private:
61 LockManager *lMgr_;
62 Transaction **trans;
63 //This is pointer to the pointer stored in the
64 //Transaction manager.
65 //If the transaction commits/aborts this pointer changes
66 //and this will get that newly allocated transaction
68 char tblName_[IDENTIFIER_LENGTH];
69 int tblID_;
70 size_t length_; //length of the tuple
71 int numFlds_;
72 void* chunkPtr_;
73 void *curTuple_;
75 Predicate *pred_;
76 ScanType scanType_;
77 //ChunkIterator *iter;
78 //BucketIter *bIter;
80 TupleIterator *iter;
81 public:
82 FieldList fldList_;
83 int numIndexes_;
84 char** indexPtr_;
85 int useIndex_;//offet in the above array indexPtr_ for scan
86 IndexInfo *idxInfo;
87 Database *db_;
88 Database *sysDB_;
90 private:
92 //copy Values from binded buffer to tuple pointed by arg
93 DbRetVal copyValuesFromBindBuffer(void *tuple);
94 DbRetVal copyValuesToBindBuffer(void *tuple);
96 DbRetVal insertIndexNode(Transaction *trans, void *indexPtr, void *tuple);
97 DbRetVal updateIndexNode(Transaction *trans, void *indexPtr, void *tuple);
98 DbRetVal deleteIndexNode(Transaction *trans, void *indexPtr, void *tuple);
100 DbRetVal createPlan();
101 Chunk* getSystemTableChunk(CatalogTableID id)
103 return sysDB_->getSystemDatabaseChunk(id);
106 public:
107 TableImpl() { db_ = NULL; chunkPtr_ = NULL; iter = NULL;
108 idxInfo = NULL; indexPtr_ = NULL; scanType_ = unknownScan;}
109 ~TableImpl();
111 void setDB(Database *db) { db_ = db; }
112 void setSystemDB(Database *db) { sysDB_ = db; }
113 void setLockManager(LockManager *lmgr) { lMgr_ = lmgr; }
114 void setTrans(Transaction **t) { trans = t; }
116 DataType getFieldType(const char *name)
117 { return fldList_.getFieldType(name); }
118 int getFieldOffset(const char *name)
119 { return fldList_.getFieldOffset(name); }
120 size_t getFieldLength(const char *name)
121 { return fldList_.getFieldLength(name); }
123 // search predicate
124 void setCondition(Condition p) { pred_ = p.getPredicate(); }
126 //binding
127 void bindFld(const char *name, void *val);
129 void markFldNull(const char *name);
130 void markFldNull(int colpos);
131 bool isFldNull(const char *name);
132 bool isFldNull(int colpos);
135 DbRetVal insertTuple();
136 DbRetVal updateTuple();
137 DbRetVal deleteTuple();
139 DbRetVal execute();
141 void* fetch();
142 DbRetVal close();
144 void setTableInfo(char *name, int tblid, size_t length,
145 int numFld, int numIdx, void *chunk);
146 friend class DatabaseManagerImpl;
150 #endif