exp changes and test case modification as we do not support mmap to
[csql.git] / include / CatalogTables.h
blob51ee816fc27b45c5239f32550e9aa4d99c3a18b2
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 ***************************************************************************/
17 #ifndef CATALOGTABLE_H
18 #define CATALOGTABLE_H
20 #include<DataType.h>
21 #include<os.h>
22 #include<Index.h>
23 #include<Debug.h>
24 #include<Util.h>
27 extern char ChunkName[MAX_CHUNKS][CHUNK_NAME_LEN];
28 class FieldList;
29 class FieldNameList;
30 class FieldIterator;
31 class ChunkIterator;
33 enum ObjectType
35 Tbl = 0,
36 hIdx = 1,
37 tIdx = 2,
40 struct Object
42 char name[64];
43 ObjectType type;
44 void *bucketChunk;
45 void *firstPage;
46 void *curPage;
49 enum CatalogTableID
51 // chunk id 0 ->userChunkTable
53 // chunk id 10->DATABASE
54 // chunk id 11->USER
55 // chunk id 12->TABLE
56 // chunk id 13->FIELD
57 // chunk id 14->ACCESS
58 // chunk id 15->INDEX
59 // chunk id 16->INDEXFIELD
61 UserChunkTableId = 0,
62 LockTableHashBucketId = 1,
63 LockTableMutexId = 2,
64 LockTableId = 3,
65 TransHasTableId = 4,
66 UndoLogTableID = 5,
69 DatabaseTableId = 10,
70 UserTableId = 11,
71 TableTableId = 12,
72 FieldTableId = 13,
73 AccessTableId = 14,
74 IndexTableId = 15,
75 IndexFieldTableId= 16,
76 ForeignKeyTableId= 17,
77 ForeignKeyFieldTableId= 18,
78 LastCatalogID = 25 //marks the end of catalog chunk ID.
82 class CTABLE
84 public:
85 char tblName_[IDENTIFIER_LENGTH];
86 int tblID_;
87 size_t length_; //length of the tuple
88 int numFlds_;
89 int numIndexes_;
90 void* chunkPtr_;
91 void* varcharChunkPtr_;
95 class CatalogTableTABLE
97 Database *systemDatabase_;
98 public:
99 CatalogTableTABLE(Database *db) { systemDatabase_ = db; }
101 //Last argument is OUT parameter which will contain the
102 //pointer to the inserted tuple
103 DbRetVal insert(const char *name, int id, size_t size,
104 int numFlds, void* chunk, void *&tptr, void *vcchunk);
106 //Second argument is OUT parameter which will contain the
107 //chunk pointer of this table
108 //Third argument is OUT parameter which will contain the
109 //pointer to the removed tuple
110 DbRetVal remove(const char *name, void *&chunk, void *&tptr);
111 DbRetVal renameTable(const char *oldName,const char *newName);
112 DbRetVal renameIndex(const char *oldName,const char *newName);
113 DbRetVal getChunkAndTblPtr(const char *name, void *&chunk, void *&tptr, void*&vcchunk);
114 DbRetVal setChunkPtr(const char *name, void *firstPage, void *curPage);
115 List getTableList();
119 class CFIELD
121 public:
122 char fldName_[IDENTIFIER_LENGTH];
123 int tblID_; //table id where this field resides
124 void* tblPtr_; //pointer to tuple in catalog table TABLE
125 DataType type_;
126 size_t length_; //length of the field
127 size_t offset_; //offset (in bytes) into tuple
128 //currently default value is supported for string and binary
129 //less than length 32 bytes
130 char defaultValueBuf_[DEFAULT_VALUE_BUF_LENGTH];
131 long long autoVal_;//[DEFAULT_VALUE_BUF_LENGTH];
132 int width_;
133 int scale_;
134 bool isNull_;
135 bool isPrimary_;
136 bool isUnique_;
137 bool isDefault_;
138 bool isAutoIncrement_;
141 class CatalogTableFIELD
143 Database *systemDatabase_;
144 public:
145 CatalogTableFIELD(Database *db) { systemDatabase_ = db; }
147 //returns -1 on error
148 DbRetVal insert(FieldIterator &iter, int tblID, void *tblPtr);
150 DbRetVal remove(void *tblPtr);
152 //II argument is OUT parameter
153 //field list is populated from the catalog table for
154 // the table pointed by tblPtr
155 void *getFieldInfo( void* tblPtr, FieldList &list);
157 //array is OUT param
158 //returns the pointer to fields for the corresponding name
159 //in field name list as an array
160 DbRetVal getFieldPtrs(FieldNameList &fldList,void *tptr, char **&array);
161 DbRetVal renameField(const char *tableName, const char *oldName, const char *newName);
164 class CUSER
166 public:
167 char userName_[IDENTIFIER_LENGTH];
168 char password_[IDENTIFIER_LENGTH];
171 class CatalogTableUSER
173 Database *systemDatabase_;
174 public:
175 CatalogTableUSER(Database *db) { systemDatabase_ = db; }
177 //returns -1 on error
178 DbRetVal insert(const char *name, const char *pass);
179 DbRetVal authenticate(const char *name, const char *pass,
180 bool &isAuthenticated, bool &isDba);
181 DbRetVal remove(const char *name);
182 DbRetVal changePass(const char *name, const char *pass);
183 List getUserList();
186 class CACCESS
188 public:
189 char userName_[IDENTIFIER_LENGTH];
190 char dbName_[IDENTIFIER_LENGTH];
193 class CDATABASEFILE
195 public:
196 int dbID_;
197 char dbName_[IDENTIFIER_LENGTH];
198 int maxChunks_;
199 size_t maxSize_; //maximum size of database
200 caddr_t dbStart_; //address where the database is mapped
204 class CINDEX
206 public:
207 char indName_[IDENTIFIER_LENGTH];
208 int tblID_; //table id of the table
209 void* tblPtr_; //pointer to tuple in catalog table TABLE
210 IndexType indexType_;
211 void* chunkPtr_; //pointer to the index chunk
212 int numFlds_;
213 int noOfBuckets_;
214 bool isUnique_;
215 void *hashNodeChunk_;
216 void *fstIndFld_;//pointer to fisrt index field
219 class CatalogTableINDEX
221 Database *systemDatabase_;
222 public:
223 CatalogTableINDEX(Database *db) { systemDatabase_ = db; }
226 //last arg is OUT parameter which will give the pointer to
227 //the index tuple
228 DbRetVal insert(const char *name, void *tblPtr, int numFlds, bool isUnique,
229 void* chunk, int bucketSize, void *hChunk, void *&tupleptr);
231 //Second argument is OUT parameter which will contain the
232 //chunk pointer of this table
233 //Third argument is OUT parameter which will contain the
234 //pointer to the removed tuple
235 DbRetVal remove(const char *name, void *&chunk, void *&hchunk, void *&iptr);
236 DbRetVal get(const char *name, void *&chunk, void *&hchunk, void *&iptr);
237 DbRetVal setChunkPtr(const char *name, ObjectType tp, void *chunk, void *firstPage, void *curPage);
239 //get the number of indexes on table pointed by tblPtr
240 int getNumIndexes(void *tblPtr);
242 char* getIndexName(void *tblPtr, int pos);
244 //gets all the index ptrs as array for the table pointed by tblPtr
245 void getIndexPtrs(void *tblPtr, char **&array);
247 static ChunkIterator getIterator(void *iptr);
248 static int getNoOfBuckets(void *iptr);
249 static int getUnique(void *iptr);
250 static char* getName(void *iptr);
251 static int getOffsetOfFirstField(void *iptr);
252 static IndexType getType(void *iptr);
256 class CINDEXFIELD
258 public:
259 void* indexPtr; //pointer to tuple in catalog table INDEX
260 void* tablePtr; //pointer to tuple in catalog table TABLE
261 void* fieldPtr; //pointer to tuple in catalog table FIELD
262 CINDEXFIELD *next;
265 class CatalogTableINDEXFIELD
267 Database *systemDatabase_;
268 public:
269 CatalogTableINDEXFIELD(Database *db) { systemDatabase_ = db; }
271 DbRetVal insert(FieldNameList &fldList, void *indexPtr,
272 void *tblPtr, char **&fptr);
274 DbRetVal remove(void *iptr);
276 DbRetVal getFieldNameAndType(void *iptr, char *&name, DataType &type);
277 DbRetVal getFieldInfo(void *index, FieldList &list);
278 void printAllIndex();
279 ListIterator getIndexListIterater(char *name);
283 class CFK
285 public:
286 char fkName_[IDENTIFIER_LENGTH];
287 void* pkTblPtr_;
288 void* fkTblPtr_;
291 class CatalogTableFK
293 Database *systemDatabase_;
294 public:
295 CatalogTableFK(Database *db) { systemDatabase_ = db; }
296 DbRetVal insert(char *name, void *tFkPtr,void *tPkPtr);
297 DbRetVal remove(void *tptr);
298 void *getFkCTable(void* tptr);
299 int getNumFkTable(void *ctptr);
300 bool isFkTable(void *ctptr);
301 void getPkTableName(void *ctptr, char **&array);
302 void getFkTableName(void *ctptr, char **&array);
303 int getNoOfPkTable(void *ctptr);
304 int getNoOfFkTable(void *ctptr);
305 DbRetVal getPkFkFieldInfo(void *cpkptr, void *cfkptr, FieldNameList &pklist,FieldNameList &pklist1);
308 class CFKFIELD
310 public:
311 void* fkPtr_;//pointer to tuple in catalog table CFK
312 void* pfFldPtr_;
313 void* fkFldPtr_;
316 class CatalogTableFKFIELD
318 Database *systemDatabase_;
319 public:
320 CatalogTableFKFIELD(Database *db) { systemDatabase_ = db; }
321 DbRetVal insert(char *cFKName, char **fkFldPtrs, char **pkFldPtrs,int totalFld);
322 DbRetVal remove(void *fptr);
325 #endif