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
27 extern char ChunkName
[MAX_CHUNKS
][CHUNK_NAME_LEN
];
35 // chunk id 0 ->userChunkTable
37 // chunk id 10->DATABASE
41 // chunk id 14->ACCESS
43 // chunk id 16->INDEXFIELD
46 LockTableHashBucketId
= 1,
67 char tblName_
[IDENTIFIER_LENGTH
];
69 size_t length_
; //length of the tuple
76 class CatalogTableTABLE
78 Database
*systemDatabase_
;
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
);
102 char fldName_
[IDENTIFIER_LENGTH
];
103 int tblID_
; //table id where this field resides
104 void* tblPtr_
; //pointer to tuple in catalog table TABLE
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
];
119 class CatalogTableFIELD
121 Database
*systemDatabase_
;
123 CatalogTableFIELD(Database
*db
) { systemDatabase_
= db
; }
125 //returns -1 on error
126 DbRetVal
insert(FieldIterator
&iter
, int tblID
, void *tblPtr
);
128 DbRetVal
remove(void *tblPtr
);
130 //II argument is OUT parameter
131 //field list is populated from the catalog table for
132 // the table pointed by tblPtr
133 void getFieldInfo( void* tblPtr
, FieldList
&list
);
136 //returns the pointer to fields for the corresponding name
137 //in field name list as an array
138 DbRetVal
getFieldPtrs(FieldNameList
&fldList
,void *tptr
, char **&array
);
144 char userName_
[IDENTIFIER_LENGTH
];
145 char password_
[IDENTIFIER_LENGTH
];
148 class CatalogTableUSER
150 Database
*systemDatabase_
;
152 CatalogTableUSER(Database
*db
) { systemDatabase_
= db
; }
154 //returns -1 on error
155 DbRetVal
insert(const char *name
, const char *pass
);
156 DbRetVal
authenticate(const char *name
, const char *pass
,
157 bool &isAuthenticated
, bool &isDba
);
158 DbRetVal
remove(const char *name
);
159 DbRetVal
changePass(const char *name
, const char *pass
);
166 char userName_
[IDENTIFIER_LENGTH
];
167 char dbName_
[IDENTIFIER_LENGTH
];
174 char dbName_
[IDENTIFIER_LENGTH
];
176 size_t maxSize_
; //maximum size of database
177 caddr_t dbStart_
; //address where the database is mapped
184 char indName_
[IDENTIFIER_LENGTH
];
185 int tblID_
; //table id of the table
186 void* tblPtr_
; //pointer to tuple in catalog table TABLE
187 IndexType indexType_
;
188 void* chunkPtr_
; //pointer to the index chunk
192 void *hashNodeChunk_
;
193 void *fstIndFld_
;//pointer to fisrt index field
196 class CatalogTableINDEX
198 Database
*systemDatabase_
;
200 CatalogTableINDEX(Database
*db
) { systemDatabase_
= db
; }
203 //last arg is OUT parameter which will give the pointer to
205 DbRetVal
insert(const char *name
, void *tblPtr
, int numFlds
, bool isUnique
,
206 void* chunk
, int bucketSize
, void *hChunk
, void *&tupleptr
);
208 //Second argument is OUT parameter which will contain the
209 //chunk pointer of this table
210 //Third argument is OUT parameter which will contain the
211 //pointer to the removed tuple
212 DbRetVal
remove(const char *name
, void *&chunk
, void *&hchunk
, void *&iptr
);
213 DbRetVal
get(const char *name
, void *&chunk
, void *&hchunk
, void *&iptr
);
215 //get the number of indexes on table pointed by tblPtr
216 int getNumIndexes(void *tblPtr
);
218 char* getIndexName(void *tblPtr
, int pos
);
220 //gets all the index ptrs as array for the table pointed by tblPtr
221 void getIndexPtrs(void *tblPtr
, char **&array
);
223 static ChunkIterator
getIterator(void *iptr
);
224 static int getNoOfBuckets(void *iptr
);
225 static int getUnique(void *iptr
);
226 static char* getName(void *iptr
);
233 void* indexPtr
; //pointer to tuple in catalog table INDEX
234 void* tablePtr
; //pointer to tuple in catalog table TABLE
235 void* fieldPtr
; //pointer to tuple in catalog table FIELD
239 class CatalogTableINDEXFIELD
241 Database
*systemDatabase_
;
243 CatalogTableINDEXFIELD(Database
*db
) { systemDatabase_
= db
; }
245 DbRetVal
insert(FieldNameList
&fldList
, void *indexPtr
,
246 void *tblPtr
, char **&fptr
);
248 DbRetVal
remove(void *iptr
);
250 DbRetVal
getFieldNameAndType(void *iptr
, char *&name
, DataType
&type
);
251 DbRetVal
getFieldInfo(void *index
, FieldList
&list
);
252 void printAllIndex();