1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
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. *
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. *
15 ***************************************************************************/
17 #ifndef CATALOGTABLE_H
18 #define CATALOGTABLE_H
33 // chunk id 0 ->userChunkTable
35 // chunk id 10->DATABASE
39 // chunk id 14->ACCESS
41 // chunk id 16->INDEXFIELD
44 LockTableHashBucketId
= 1,
65 char tblName_
[IDENTIFIER_LENGTH
];
67 size_t length_
; //length of the tuple
74 class CatalogTableTABLE
76 Database
*systemDatabase_
;
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
);
100 char fldName_
[IDENTIFIER_LENGTH
];
101 int tblID_
; //table id where this field resides
102 void* tblPtr_
; //pointer to tuple in catalog table TABLE
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
];
117 class CatalogTableFIELD
119 Database
*systemDatabase_
;
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
);
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
);
142 char userName_
[IDENTIFIER_LENGTH
];
143 char password_
[IDENTIFIER_LENGTH
];
146 class CatalogTableUSER
148 Database
*systemDatabase_
;
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
);
164 char userName_
[IDENTIFIER_LENGTH
];
165 char dbName_
[IDENTIFIER_LENGTH
];
172 char dbName_
[IDENTIFIER_LENGTH
];
174 size_t maxSize_
; //maximum size of database
175 caddr_t dbStart_
; //address where the database is mapped
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
190 void *hashNodeChunk_
;
194 class CatalogTableINDEX
196 Database
*systemDatabase_
;
198 CatalogTableINDEX(Database
*db
) { systemDatabase_
= db
; }
201 //last arg is OUT parameter which will give the pointer to
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
);
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_
;
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
);