Changed the condition. Better code
[csql.git] / include / CatalogTables.h
blobf2b9c14729bd6e3a7dd4c0fc7e59ee7e5a6ab227
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>
25 class FieldList;
26 class FieldNameList;
27 class FieldIterator;
28 class ChunkIterator;
30 enum CatalogTableID
32 // chunk id 0 ->userChunkTable
34 // chunk id 10->DATABASE
35 // chunk id 11->USER
36 // chunk id 12->TABLE
37 // chunk id 13->FIELD
38 // chunk id 14->ACCESS
39 // chunk id 15->INDEX
40 // chunk id 16->INDEXFIELD
42 UserChunkTableId = 0,
43 LockTableHashBucketId = 1,
44 LockTableMutexId = 2,
45 LockTableId = 3,
46 TransHasTableId = 4,
47 UndoLogTableID = 5,
50 DatabaseTableId = 10,
51 UserTableId = 11,
52 TableTableId = 12,
53 FieldTableId = 13,
54 AccessTableId = 14,
55 IndexTableId = 15,
56 IndexFieldTableId= 16
61 class TABLE
63 public:
64 char tblName_[IDENTIFIER_LENGTH];
65 int tblID_;
66 size_t length_; //length of the tuple
67 int numFlds_;
68 int numIndexes_;
69 void* chunkPtr_;
73 class CatalogTableTABLE
75 Database *systemDatabase_;
76 public:
77 CatalogTableTABLE(Database *db) { systemDatabase_ = db; }
79 //Last argument is OUT parameter which will contain the
80 //pointer to the inserted tuple
81 DbRetVal insert(const char *name, int id, size_t size,
82 int numFlds, void* chunk, void *&tptr);
84 //Second argument is OUT parameter which will contain the
85 //chunk pointer of this table
86 //Third argument is OUT parameter which will contain the
87 //pointer to the removed tuple
88 DbRetVal remove(const char *name, void *&chunk, void *&tptr);
90 DbRetVal getChunkAndTblPtr(const char *name, void *&chunk, void *&tptr);
94 class FIELD
96 public:
97 char fldName_[IDENTIFIER_LENGTH];
98 int tblID_; //table id where this field resides
99 void* tblPtr_; //pointer to tuple in catalog table TABLE
100 DataType type_;
101 size_t length_; //length of the field
102 size_t offset_; //offset (in bytes) into tuple
103 //currently default value is supported for string and binary
104 //less than length 32 bytes
105 char defaultValueBuf_[DEFAULT_VALUE_BUF_LENGTH];
106 bool isNull_;
107 bool isPrimary_;
108 bool isDefault_;
109 int width_;
110 int scale_;
113 class CatalogTableFIELD
115 Database *systemDatabase_;
116 public:
117 CatalogTableFIELD(Database *db) { systemDatabase_ = db; }
119 //returns -1 on error
120 DbRetVal insert(FieldIterator &iter, int tblID, void *tblPtr);
122 DbRetVal remove(void *tblPtr);
124 //II argument is OUT parameter
125 //field list is populated from the catalog table for
126 // the table pointed by tblPtr
127 void getFieldInfo( void* tblPtr, FieldList &list);
129 //array is OUT param
130 //returns the pointer to fields for the corresponding name
131 //in field name list as an array
132 DbRetVal getFieldPtrs(FieldNameList &fldList,void *tptr, char **&array);
135 class USER
137 public:
138 char userName_[IDENTIFIER_LENGTH];
139 char password_[IDENTIFIER_LENGTH];
142 class CatalogTableUSER
144 Database *systemDatabase_;
145 public:
146 CatalogTableUSER(Database *db) { systemDatabase_ = db; }
148 //returns -1 on error
149 DbRetVal insert(const char *name, const char *pass);
150 DbRetVal authenticate(const char *name, const char *pass,
151 bool &isAuthenticated, bool &isDba);
152 DbRetVal remove(const char *name);
153 DbRetVal changePass(const char *name, const char *pass);
157 class ACCESS
159 public:
160 char userName_[IDENTIFIER_LENGTH];
161 char dbName_[IDENTIFIER_LENGTH];
164 class DATABASEFILE
166 public:
167 int dbID_;
168 char dbName_[IDENTIFIER_LENGTH];
169 int maxChunks_;
170 size_t maxSize_; //maximum size of database
171 caddr_t dbStart_; //address where the database is mapped
175 class INDEX
177 public:
178 char indName_[IDENTIFIER_LENGTH];
179 int tblID_; //table id of the table
180 void* tblPtr_; //pointer to tuple in catalog table TABLE
181 IndexType indexType_;
182 void* chunkPtr_; //pointer to the index chunk
183 int numFlds_;
184 int noOfBuckets_;
185 bool isPrimary_;
186 void *hashNodeChunk_;
190 class CatalogTableINDEX
192 Database *systemDatabase_;
193 public:
194 CatalogTableINDEX(Database *db) { systemDatabase_ = db; }
197 //last arg is OUT parameter which will give the pointer to
198 //the index tuple
199 DbRetVal insert(const char *name, void *tblPtr, int numFlds,
200 void* chunk, int bucketSize, void *hChunk, void *&tupleptr);
202 //Second argument is OUT parameter which will contain the
203 //chunk pointer of this table
204 //Third argument is OUT parameter which will contain the
205 //pointer to the removed tuple
206 DbRetVal remove(const char *name, void *&chunk, void *&hchunk, void *&iptr);
208 //get the number of indexes on table pointed by tblPtr
209 int getNumIndexes(void *tblPtr);
211 char* getIndexName(void *tblPtr, int pos);
213 //gets all the index ptrs as array for the table pointed by tblPtr
214 void getIndexPtrs(void *tblPtr, char **&array);
216 static ChunkIterator getIterator(void *iptr);
217 static int getNoOfBuckets(void *iptr);
221 class INDEXFIELD
223 public:
224 void* indexPtr; //pointer to tuple in catalog table INDEX
225 void* tablePtr; //pointer to tuple in catalog table TABLE
226 void* fieldPtr; //pointer to tuple in catalog table FIELD
230 class CatalogTableINDEXFIELD
232 Database *systemDatabase_;
233 public:
234 CatalogTableINDEXFIELD(Database *db) { systemDatabase_ = db; }
236 DbRetVal insert(FieldNameList &fldList, void *indexPtr,
237 void *tblPtr, char **&fptr);
239 DbRetVal remove(void *iptr);
241 DbRetVal getFieldNameAndType(void *iptr, char *&name, DataType &type);
244 #endif