submitting patch from enterprise version
[csql.git] / include / CatalogTables.h
blobc70031ade8c4e31186fa500d8d5581e271fe2be9
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 CatalogTableID
35 // chunk id 0 ->userChunkTable
37 // chunk id 10->DATABASE
38 // chunk id 11->USER
39 // chunk id 12->TABLE
40 // chunk id 13->FIELD
41 // chunk id 14->ACCESS
42 // chunk id 15->INDEX
43 // chunk id 16->INDEXFIELD
45 UserChunkTableId = 0,
46 LockTableHashBucketId = 1,
47 LockTableMutexId = 2,
48 LockTableId = 3,
49 TransHasTableId = 4,
50 UndoLogTableID = 5,
53 DatabaseTableId = 10,
54 UserTableId = 11,
55 TableTableId = 12,
56 FieldTableId = 13,
57 AccessTableId = 14,
58 IndexTableId = 15,
59 IndexFieldTableId= 16
64 class CTABLE
66 public:
67 char tblName_[IDENTIFIER_LENGTH];
68 int tblID_;
69 size_t length_; //length of the tuple
70 int numFlds_;
71 int numIndexes_;
72 void* chunkPtr_;
76 class CatalogTableTABLE
78 Database *systemDatabase_;
79 public:
80 CatalogTableTABLE(Database *db) { systemDatabase_ = db; }
82 //Last argument is OUT parameter which will contain the
83 //pointer to the inserted tuple
84 DbRetVal insert(const char *name, int id, size_t size,
85 int numFlds, void* chunk, void *&tptr);
87 //Second argument is OUT parameter which will contain the
88 //chunk pointer of this table
89 //Third argument is OUT parameter which will contain the
90 //pointer to the removed tuple
91 DbRetVal remove(const char *name, void *&chunk, void *&tptr);
93 DbRetVal getChunkAndTblPtr(const char *name, void *&chunk, void *&tptr);
95 List getTableList();
99 class CFIELD
101 public:
102 char fldName_[IDENTIFIER_LENGTH];
103 int tblID_; //table id where this field resides
104 void* tblPtr_; //pointer to tuple in catalog table TABLE
105 DataType type_;
106 size_t length_; //length of the field
107 size_t offset_; //offset (in bytes) into tuple
108 //currently default value is supported for string and binary
109 //less than length 32 bytes
110 char defaultValueBuf_[DEFAULT_VALUE_BUF_LENGTH];
111 bool isNull_;
112 bool isPrimary_;
113 bool isUnique_;
114 bool isDefault_;
115 bool isAutoIncrement_;
116 long long autoVal_;
117 int width_;
118 int scale_;
121 class CatalogTableFIELD
123 Database *systemDatabase_;
124 public:
125 CatalogTableFIELD(Database *db) { systemDatabase_ = db; }
127 //returns -1 on error
128 DbRetVal insert(FieldIterator &iter, int tblID, void *tblPtr);
130 DbRetVal remove(void *tblPtr);
132 //II argument is OUT parameter
133 //field list is populated from the catalog table for
134 // the table pointed by tblPtr
135 void *getFieldInfo( void* tblPtr, FieldList &list);
137 //array is OUT param
138 //returns the pointer to fields for the corresponding name
139 //in field name list as an array
140 DbRetVal getFieldPtrs(FieldNameList &fldList,void *tptr, char **&array);
143 class CUSER
145 public:
146 char userName_[IDENTIFIER_LENGTH];
147 char password_[IDENTIFIER_LENGTH];
150 class CatalogTableUSER
152 Database *systemDatabase_;
153 public:
154 CatalogTableUSER(Database *db) { systemDatabase_ = db; }
156 //returns -1 on error
157 DbRetVal insert(const char *name, const char *pass);
158 DbRetVal authenticate(const char *name, const char *pass,
159 bool &isAuthenticated, bool &isDba);
160 DbRetVal remove(const char *name);
161 DbRetVal changePass(const char *name, const char *pass);
165 class CACCESS
167 public:
168 char userName_[IDENTIFIER_LENGTH];
169 char dbName_[IDENTIFIER_LENGTH];
172 class CDATABASEFILE
174 public:
175 int dbID_;
176 char dbName_[IDENTIFIER_LENGTH];
177 int maxChunks_;
178 size_t maxSize_; //maximum size of database
179 caddr_t dbStart_; //address where the database is mapped
183 class CINDEX
185 public:
186 char indName_[IDENTIFIER_LENGTH];
187 int tblID_; //table id of the table
188 void* tblPtr_; //pointer to tuple in catalog table TABLE
189 IndexType indexType_;
190 void* chunkPtr_; //pointer to the index chunk
191 int numFlds_;
192 int noOfBuckets_;
193 bool isUnique_;
194 void *hashNodeChunk_;
195 void *fstIndFld_;//pointer to fisrt index field
198 class CatalogTableINDEX
200 Database *systemDatabase_;
201 public:
202 CatalogTableINDEX(Database *db) { systemDatabase_ = db; }
205 //last arg is OUT parameter which will give the pointer to
206 //the index tuple
207 DbRetVal insert(const char *name, void *tblPtr, int numFlds, bool isUnique,
208 void* chunk, int bucketSize, void *hChunk, void *&tupleptr);
210 //Second argument is OUT parameter which will contain the
211 //chunk pointer of this table
212 //Third argument is OUT parameter which will contain the
213 //pointer to the removed tuple
214 DbRetVal remove(const char *name, void *&chunk, void *&hchunk, void *&iptr);
215 DbRetVal get(const char *name, void *&chunk, void *&hchunk, void *&iptr);
217 //get the number of indexes on table pointed by tblPtr
218 int getNumIndexes(void *tblPtr);
220 char* getIndexName(void *tblPtr, int pos);
222 //gets all the index ptrs as array for the table pointed by tblPtr
223 void getIndexPtrs(void *tblPtr, char **&array);
225 static ChunkIterator getIterator(void *iptr);
226 static int getNoOfBuckets(void *iptr);
227 static int getUnique(void *iptr);
228 static char* getName(void *iptr);
232 class CINDEXFIELD
234 public:
235 void* indexPtr; //pointer to tuple in catalog table INDEX
236 void* tablePtr; //pointer to tuple in catalog table TABLE
237 void* fieldPtr; //pointer to tuple in catalog table FIELD
238 CINDEXFIELD *next;
241 class CatalogTableINDEXFIELD
243 Database *systemDatabase_;
244 public:
245 CatalogTableINDEXFIELD(Database *db) { systemDatabase_ = db; }
247 DbRetVal insert(FieldNameList &fldList, void *indexPtr,
248 void *tblPtr, char **&fptr);
250 DbRetVal remove(void *iptr);
252 DbRetVal getFieldNameAndType(void *iptr, char *&name, DataType &type);
253 DbRetVal getFieldInfo(void *index, FieldList &list);
254 void printAllIndex();
257 #endif