fixing readmes in examples
[csql.git] / include / CatalogTables.h
blobea7371ef4f6d94bc52bc644d9b2052ba0d3b7285
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>
26 class FieldList;
27 class FieldNameList;
28 class FieldIterator;
29 class ChunkIterator;
31 enum CatalogTableID
33 // chunk id 0 ->userChunkTable
35 // chunk id 10->DATABASE
36 // chunk id 11->USER
37 // chunk id 12->TABLE
38 // chunk id 13->FIELD
39 // chunk id 14->ACCESS
40 // chunk id 15->INDEX
41 // chunk id 16->INDEXFIELD
43 UserChunkTableId = 0,
44 LockTableHashBucketId = 1,
45 LockTableMutexId = 2,
46 LockTableId = 3,
47 TransHasTableId = 4,
48 UndoLogTableID = 5,
51 DatabaseTableId = 10,
52 UserTableId = 11,
53 TableTableId = 12,
54 FieldTableId = 13,
55 AccessTableId = 14,
56 IndexTableId = 15,
57 IndexFieldTableId= 16
62 class TABLE
64 public:
65 char tblName_[IDENTIFIER_LENGTH];
66 int tblID_;
67 size_t length_; //length of the tuple
68 int numFlds_;
69 int numIndexes_;
70 void* chunkPtr_;
74 class CatalogTableTABLE
76 Database *systemDatabase_;
77 public:
78 CatalogTableTABLE(Database *db) { systemDatabase_ = db; }
80 //Last argument is OUT parameter which will contain the
81 //pointer to the inserted tuple
82 DbRetVal insert(const char *name, int id, size_t size,
83 int numFlds, void* chunk, void *&tptr);
85 //Second argument is OUT parameter which will contain the
86 //chunk pointer of this table
87 //Third argument is OUT parameter which will contain the
88 //pointer to the removed tuple
89 DbRetVal remove(const char *name, void *&chunk, void *&tptr);
91 DbRetVal getChunkAndTblPtr(const char *name, void *&chunk, void *&tptr);
93 List getTableList();
97 class FIELD
99 public:
100 char fldName_[IDENTIFIER_LENGTH];
101 int tblID_; //table id where this field resides
102 void* tblPtr_; //pointer to tuple in catalog table TABLE
103 DataType type_;
104 size_t length_; //length of the field
105 size_t offset_; //offset (in bytes) into tuple
106 //currently default value is supported for string and binary
107 //less than length 32 bytes
108 char defaultValueBuf_[DEFAULT_VALUE_BUF_LENGTH];
109 bool isNull_;
110 bool isPrimary_;
111 bool isUnique_;
112 bool isDefault_;
113 int width_;
114 int scale_;
117 class CatalogTableFIELD
119 Database *systemDatabase_;
120 public:
121 CatalogTableFIELD(Database *db) { systemDatabase_ = db; }
123 //returns -1 on error
124 DbRetVal insert(FieldIterator &iter, int tblID, void *tblPtr);
126 DbRetVal remove(void *tblPtr);
128 //II argument is OUT parameter
129 //field list is populated from the catalog table for
130 // the table pointed by tblPtr
131 void getFieldInfo( void* tblPtr, FieldList &list);
133 //array is OUT param
134 //returns the pointer to fields for the corresponding name
135 //in field name list as an array
136 DbRetVal getFieldPtrs(FieldNameList &fldList,void *tptr, char **&array);
139 class USER
141 public:
142 char userName_[IDENTIFIER_LENGTH];
143 char password_[IDENTIFIER_LENGTH];
146 class CatalogTableUSER
148 Database *systemDatabase_;
149 public:
150 CatalogTableUSER(Database *db) { systemDatabase_ = db; }
152 //returns -1 on error
153 DbRetVal insert(const char *name, const char *pass);
154 DbRetVal authenticate(const char *name, const char *pass,
155 bool &isAuthenticated, bool &isDba);
156 DbRetVal remove(const char *name);
157 DbRetVal changePass(const char *name, const char *pass);
161 class ACCESS
163 public:
164 char userName_[IDENTIFIER_LENGTH];
165 char dbName_[IDENTIFIER_LENGTH];
168 class DATABASEFILE
170 public:
171 int dbID_;
172 char dbName_[IDENTIFIER_LENGTH];
173 int maxChunks_;
174 size_t maxSize_; //maximum size of database
175 caddr_t dbStart_; //address where the database is mapped
179 class INDEX
181 public:
182 char indName_[IDENTIFIER_LENGTH];
183 int tblID_; //table id of the table
184 void* tblPtr_; //pointer to tuple in catalog table TABLE
185 IndexType indexType_;
186 void* chunkPtr_; //pointer to the index chunk
187 int numFlds_;
188 int noOfBuckets_;
189 bool isUnique_;
190 void *hashNodeChunk_;
194 class CatalogTableINDEX
196 Database *systemDatabase_;
197 public:
198 CatalogTableINDEX(Database *db) { systemDatabase_ = db; }
201 //last arg is OUT parameter which will give the pointer to
202 //the index tuple
203 DbRetVal insert(const char *name, void *tblPtr, int numFlds, bool isUnique,
204 void* chunk, int bucketSize, void *hChunk, void *&tupleptr);
206 //Second argument is OUT parameter which will contain the
207 //chunk pointer of this table
208 //Third argument is OUT parameter which will contain the
209 //pointer to the removed tuple
210 DbRetVal remove(const char *name, void *&chunk, void *&hchunk, void *&iptr);
211 DbRetVal get(const char *name, void *&chunk, void *&hchunk, void *&iptr);
213 //get the number of indexes on table pointed by tblPtr
214 int getNumIndexes(void *tblPtr);
216 char* getIndexName(void *tblPtr, int pos);
218 //gets all the index ptrs as array for the table pointed by tblPtr
219 void getIndexPtrs(void *tblPtr, char **&array);
221 static ChunkIterator getIterator(void *iptr);
222 static int getNoOfBuckets(void *iptr);
223 static int getUnique(void *iptr);
224 static char* getName(void *iptr);
228 class INDEXFIELD
230 public:
231 void* indexPtr; //pointer to tuple in catalog table INDEX
232 void* tablePtr; //pointer to tuple in catalog table TABLE
233 void* fieldPtr; //pointer to tuple in catalog table FIELD
237 class CatalogTableINDEXFIELD
239 Database *systemDatabase_;
240 public:
241 CatalogTableINDEXFIELD(Database *db) { systemDatabase_ = db; }
243 DbRetVal insert(FieldNameList &fldList, void *indexPtr,
244 void *tblPtr, char **&fptr);
246 DbRetVal remove(void *iptr);
248 DbRetVal getFieldNameAndType(void *iptr, char *&name, DataType &type);
251 #endif