First cut tiny sql engine changes
[csql.git] / include / TableImpl.h
blobb7b571df87563695ef5767d29f8375ce8ca1eaad
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_;
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; pred_ = NULL;}
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 DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info)
124 { return fldList_.getFieldInfo(fieldName, info); }
126 FieldNameList getFieldNameList();
128 // search predicate
129 void setCondition(Condition *p)
130 { if (p) { pred_ = p->getPredicate(); }else pred_ = NULL;}
132 //binding
133 void bindFld(const char *name, void *val);
135 void markFldNull(const char *name);
136 void markFldNull(int colpos);
137 bool isFldNull(const char *name);
138 bool isFldNull(int colpos);
141 void clearFldNull(const char *name);
142 void clearFldNull(int colpos);
145 DbRetVal insertTuple();
146 DbRetVal updateTuple();
147 DbRetVal deleteTuple();
149 DbRetVal execute();
151 void* fetch();
152 void* fetchNoBind();
154 DbRetVal close();
157 long spaceUsed();
159 long numTuples();
162 void setTableInfo(char *name, int tblid, size_t length,
163 int numFld, int numIdx, void *chunk);
164 friend class DatabaseManagerImpl;
168 #endif