adding more debug messages to odbc
[csql.git] / include / CatalogTables.h
blob8886be437d9602fd3f651ec732cc1e9c11b54357
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
81 class CTABLE
83 public:
84 char tblName_[IDENTIFIER_LENGTH];
85 int tblID_;
86 size_t length_; //length of the tuple
87 int numFlds_;
88 int numIndexes_;
89 void* chunkPtr_;
93 class CatalogTableTABLE
95 Database *systemDatabase_;
96 public:
97 CatalogTableTABLE(Database *db) { systemDatabase_ = db; }
99 //Last argument is OUT parameter which will contain the
100 //pointer to the inserted tuple
101 DbRetVal insert(const char *name, int id, size_t size,
102 int numFlds, void* chunk, void *&tptr);
104 //Second argument is OUT parameter which will contain the
105 //chunk pointer of this table
106 //Third argument is OUT parameter which will contain the
107 //pointer to the removed tuple
108 DbRetVal remove(const char *name, void *&chunk, void *&tptr);
110 DbRetVal getChunkAndTblPtr(const char *name, void *&chunk, void *&tptr);
111 DbRetVal setChunkPtr(const char *name, void *firstPage, void *curPage);
112 List getTableList();
116 class CFIELD
118 public:
119 char fldName_[IDENTIFIER_LENGTH];
120 int tblID_; //table id where this field resides
121 void* tblPtr_; //pointer to tuple in catalog table TABLE
122 DataType type_;
123 size_t length_; //length of the field
124 size_t offset_; //offset (in bytes) into tuple
125 //currently default value is supported for string and binary
126 //less than length 32 bytes
127 char defaultValueBuf_[DEFAULT_VALUE_BUF_LENGTH];
128 long long autoVal_;//[DEFAULT_VALUE_BUF_LENGTH];
129 int width_;
130 int scale_;
131 bool isNull_;
132 bool isPrimary_;
133 bool isUnique_;
134 bool isDefault_;
135 bool isAutoIncrement_;
138 class CatalogTableFIELD
140 Database *systemDatabase_;
141 public:
142 CatalogTableFIELD(Database *db) { systemDatabase_ = db; }
144 //returns -1 on error
145 DbRetVal insert(FieldIterator &iter, int tblID, void *tblPtr);
147 DbRetVal remove(void *tblPtr);
149 //II argument is OUT parameter
150 //field list is populated from the catalog table for
151 // the table pointed by tblPtr
152 void *getFieldInfo( void* tblPtr, FieldList &list);
154 //array is OUT param
155 //returns the pointer to fields for the corresponding name
156 //in field name list as an array
157 DbRetVal getFieldPtrs(FieldNameList &fldList,void *tptr, char **&array);
160 class CUSER
162 public:
163 char userName_[IDENTIFIER_LENGTH];
164 char password_[IDENTIFIER_LENGTH];
167 class CatalogTableUSER
169 Database *systemDatabase_;
170 public:
171 CatalogTableUSER(Database *db) { systemDatabase_ = db; }
173 //returns -1 on error
174 DbRetVal insert(const char *name, const char *pass);
175 DbRetVal authenticate(const char *name, const char *pass,
176 bool &isAuthenticated, bool &isDba);
177 DbRetVal remove(const char *name);
178 DbRetVal changePass(const char *name, const char *pass);
179 List getUserList();
182 class CACCESS
184 public:
185 char userName_[IDENTIFIER_LENGTH];
186 char dbName_[IDENTIFIER_LENGTH];
189 class CDATABASEFILE
191 public:
192 int dbID_;
193 char dbName_[IDENTIFIER_LENGTH];
194 int maxChunks_;
195 size_t maxSize_; //maximum size of database
196 caddr_t dbStart_; //address where the database is mapped
200 class CINDEX
202 public:
203 char indName_[IDENTIFIER_LENGTH];
204 int tblID_; //table id of the table
205 void* tblPtr_; //pointer to tuple in catalog table TABLE
206 IndexType indexType_;
207 void* chunkPtr_; //pointer to the index chunk
208 int numFlds_;
209 int noOfBuckets_;
210 bool isUnique_;
211 void *hashNodeChunk_;
212 void *fstIndFld_;//pointer to fisrt index field
215 class CatalogTableINDEX
217 Database *systemDatabase_;
218 public:
219 CatalogTableINDEX(Database *db) { systemDatabase_ = db; }
222 //last arg is OUT parameter which will give the pointer to
223 //the index tuple
224 DbRetVal insert(const char *name, void *tblPtr, int numFlds, bool isUnique,
225 void* chunk, int bucketSize, void *hChunk, void *&tupleptr);
227 //Second argument is OUT parameter which will contain the
228 //chunk pointer of this table
229 //Third argument is OUT parameter which will contain the
230 //pointer to the removed tuple
231 DbRetVal remove(const char *name, void *&chunk, void *&hchunk, void *&iptr);
232 DbRetVal get(const char *name, void *&chunk, void *&hchunk, void *&iptr);
233 DbRetVal setChunkPtr(const char *name, ObjectType tp, void *chunk, void *firstPage, void *curPage);
235 //get the number of indexes on table pointed by tblPtr
236 int getNumIndexes(void *tblPtr);
238 char* getIndexName(void *tblPtr, int pos);
240 //gets all the index ptrs as array for the table pointed by tblPtr
241 void getIndexPtrs(void *tblPtr, char **&array);
243 static ChunkIterator getIterator(void *iptr);
244 static int getNoOfBuckets(void *iptr);
245 static int getUnique(void *iptr);
246 static char* getName(void *iptr);
247 static int getOffsetOfFirstField(void *iptr);
248 static IndexType getType(void *iptr);
252 class CINDEXFIELD
254 public:
255 void* indexPtr; //pointer to tuple in catalog table INDEX
256 void* tablePtr; //pointer to tuple in catalog table TABLE
257 void* fieldPtr; //pointer to tuple in catalog table FIELD
258 CINDEXFIELD *next;
261 class CatalogTableINDEXFIELD
263 Database *systemDatabase_;
264 public:
265 CatalogTableINDEXFIELD(Database *db) { systemDatabase_ = db; }
267 DbRetVal insert(FieldNameList &fldList, void *indexPtr,
268 void *tblPtr, char **&fptr);
270 DbRetVal remove(void *iptr);
272 DbRetVal getFieldNameAndType(void *iptr, char *&name, DataType &type);
273 DbRetVal getFieldInfo(void *index, FieldList &list);
274 void printAllIndex();
275 ListIterator getIndexListIterater(char *name);
279 class CFK
281 public:
282 char fkName_[IDENTIFIER_LENGTH];
283 void* pkTblPtr_;
284 void* fkTblPtr_;
287 class CatalogTableFK
289 Database *systemDatabase_;
290 public:
291 CatalogTableFK(Database *db) { systemDatabase_ = db; }
292 DbRetVal insert(char *name, void *tFkPtr,void *tPkPtr);
293 DbRetVal remove(void *tptr);
294 void *getFkCTable(void* tptr);
295 int getNumFkTable(void *ctptr);
296 bool isFkTable(void *ctptr);
297 void getPkTableName(void *ctptr, char **&array);
298 void getFkTableName(void *ctptr, char **&array);
299 int getNoOfPkTable(void *ctptr);
300 int getNoOfFkTable(void *ctptr);
301 DbRetVal getPkFkFieldInfo(void *cpkptr, void *cfkptr, FieldNameList &pklist,FieldNameList &pklist1);
304 class CFKFIELD
306 public:
307 void* fkPtr_;//pointer to tuple in catalog table CFK
308 void* pfFldPtr_;
309 void* fkFldPtr_;
312 class CatalogTableFKFIELD
314 Database *systemDatabase_;
315 public:
316 CatalogTableFKFIELD(Database *db) { systemDatabase_ = db; }
317 DbRetVal insert(char *cFKName, char **fkFldPtrs, char **pkFldPtrs,int totalFld);
318 DbRetVal remove(void *fptr);
321 #endif