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
];
51 // chunk id 0 ->userChunkTable
53 // chunk id 10->DATABASE
57 // chunk id 14->ACCESS
59 // chunk id 16->INDEXFIELD
62 LockTableHashBucketId
= 1,
75 IndexFieldTableId
= 16,
76 ForeignKeyTableId
= 17,
77 ForeignKeyFieldTableId
= 18,
78 LastCatalogID
= 25 //marks the end of catalog chunk ID.
85 char tblName_
[IDENTIFIER_LENGTH
];
87 size_t length_
; //length of the tuple
91 void* varcharChunkPtr_
;
95 class CatalogTableTABLE
97 Database
*systemDatabase_
;
99 CatalogTableTABLE(Database
*db
) { systemDatabase_
= db
; }
101 //Last argument is OUT parameter which will contain the
102 //pointer to the inserted tuple
103 DbRetVal
insert(const char *name
, int id
, size_t size
,
104 int numFlds
, void* chunk
, void *&tptr
, void *vcchunk
);
106 //Second argument is OUT parameter which will contain the
107 //chunk pointer of this table
108 //Third argument is OUT parameter which will contain the
109 //pointer to the removed tuple
110 DbRetVal
remove(const char *name
, void *&chunk
, void *&tptr
);
111 DbRetVal
renameTable(const char *oldName
,const char *newName
);
112 DbRetVal
getChunkAndTblPtr(const char *name
, void *&chunk
, void *&tptr
, void*&vcchunk
);
113 DbRetVal
setChunkPtr(const char *name
, void *firstPage
, void *curPage
);
121 char fldName_
[IDENTIFIER_LENGTH
];
122 int tblID_
; //table id where this field resides
123 void* tblPtr_
; //pointer to tuple in catalog table TABLE
125 size_t length_
; //length of the field
126 size_t offset_
; //offset (in bytes) into tuple
127 //currently default value is supported for string and binary
128 //less than length 32 bytes
129 char defaultValueBuf_
[DEFAULT_VALUE_BUF_LENGTH
];
130 long long autoVal_
;//[DEFAULT_VALUE_BUF_LENGTH];
137 bool isAutoIncrement_
;
140 class CatalogTableFIELD
142 Database
*systemDatabase_
;
144 CatalogTableFIELD(Database
*db
) { systemDatabase_
= db
; }
146 //returns -1 on error
147 DbRetVal
insert(FieldIterator
&iter
, int tblID
, void *tblPtr
);
149 DbRetVal
remove(void *tblPtr
);
151 //II argument is OUT parameter
152 //field list is populated from the catalog table for
153 // the table pointed by tblPtr
154 void *getFieldInfo( void* tblPtr
, FieldList
&list
);
157 //returns the pointer to fields for the corresponding name
158 //in field name list as an array
159 DbRetVal
getFieldPtrs(FieldNameList
&fldList
,void *tptr
, char **&array
);
160 DbRetVal
renameField(const char *tableName
, const char *oldName
, const char *newName
);
166 char userName_
[IDENTIFIER_LENGTH
];
167 char password_
[IDENTIFIER_LENGTH
];
170 class CatalogTableUSER
172 Database
*systemDatabase_
;
174 CatalogTableUSER(Database
*db
) { systemDatabase_
= db
; }
176 //returns -1 on error
177 DbRetVal
insert(const char *name
, const char *pass
);
178 DbRetVal
authenticate(const char *name
, const char *pass
,
179 bool &isAuthenticated
, bool &isDba
);
180 DbRetVal
remove(const char *name
);
181 DbRetVal
changePass(const char *name
, const char *pass
);
188 char userName_
[IDENTIFIER_LENGTH
];
189 char dbName_
[IDENTIFIER_LENGTH
];
196 char dbName_
[IDENTIFIER_LENGTH
];
198 size_t maxSize_
; //maximum size of database
199 caddr_t dbStart_
; //address where the database is mapped
206 char indName_
[IDENTIFIER_LENGTH
];
207 int tblID_
; //table id of the table
208 void* tblPtr_
; //pointer to tuple in catalog table TABLE
209 IndexType indexType_
;
210 void* chunkPtr_
; //pointer to the index chunk
214 void *hashNodeChunk_
;
215 void *fstIndFld_
;//pointer to fisrt index field
218 class CatalogTableINDEX
220 Database
*systemDatabase_
;
222 CatalogTableINDEX(Database
*db
) { systemDatabase_
= db
; }
225 //last arg is OUT parameter which will give the pointer to
227 DbRetVal
insert(const char *name
, void *tblPtr
, int numFlds
, bool isUnique
,
228 void* chunk
, int bucketSize
, void *hChunk
, void *&tupleptr
);
230 //Second argument is OUT parameter which will contain the
231 //chunk pointer of this table
232 //Third argument is OUT parameter which will contain the
233 //pointer to the removed tuple
234 DbRetVal
remove(const char *name
, void *&chunk
, void *&hchunk
, void *&iptr
);
235 DbRetVal
get(const char *name
, void *&chunk
, void *&hchunk
, void *&iptr
);
236 DbRetVal
setChunkPtr(const char *name
, ObjectType tp
, void *chunk
, void *firstPage
, void *curPage
);
238 //get the number of indexes on table pointed by tblPtr
239 int getNumIndexes(void *tblPtr
);
241 char* getIndexName(void *tblPtr
, int pos
);
243 //gets all the index ptrs as array for the table pointed by tblPtr
244 void getIndexPtrs(void *tblPtr
, char **&array
);
246 static ChunkIterator
getIterator(void *iptr
);
247 static int getNoOfBuckets(void *iptr
);
248 static int getUnique(void *iptr
);
249 static char* getName(void *iptr
);
250 static int getOffsetOfFirstField(void *iptr
);
251 static IndexType
getType(void *iptr
);
258 void* indexPtr
; //pointer to tuple in catalog table INDEX
259 void* tablePtr
; //pointer to tuple in catalog table TABLE
260 void* fieldPtr
; //pointer to tuple in catalog table FIELD
264 class CatalogTableINDEXFIELD
266 Database
*systemDatabase_
;
268 CatalogTableINDEXFIELD(Database
*db
) { systemDatabase_
= db
; }
270 DbRetVal
insert(FieldNameList
&fldList
, void *indexPtr
,
271 void *tblPtr
, char **&fptr
);
273 DbRetVal
remove(void *iptr
);
275 DbRetVal
getFieldNameAndType(void *iptr
, char *&name
, DataType
&type
);
276 DbRetVal
getFieldInfo(void *index
, FieldList
&list
);
277 void printAllIndex();
278 ListIterator
getIndexListIterater(char *name
);
285 char fkName_
[IDENTIFIER_LENGTH
];
292 Database
*systemDatabase_
;
294 CatalogTableFK(Database
*db
) { systemDatabase_
= db
; }
295 DbRetVal
insert(char *name
, void *tFkPtr
,void *tPkPtr
);
296 DbRetVal
remove(void *tptr
);
297 void *getFkCTable(void* tptr
);
298 int getNumFkTable(void *ctptr
);
299 bool isFkTable(void *ctptr
);
300 void getPkTableName(void *ctptr
, char **&array
);
301 void getFkTableName(void *ctptr
, char **&array
);
302 int getNoOfPkTable(void *ctptr
);
303 int getNoOfFkTable(void *ctptr
);
304 DbRetVal
getPkFkFieldInfo(void *cpkptr
, void *cfkptr
, FieldNameList
&pklist
,FieldNameList
&pklist1
);
310 void* fkPtr_
;//pointer to tuple in catalog table CFK
315 class CatalogTableFKFIELD
317 Database
*systemDatabase_
;
319 CatalogTableFKFIELD(Database
*db
) { systemDatabase_
= db
; }
320 DbRetVal
insert(char *cFKName
, char **fkFldPtrs
, char **pkFldPtrs
,int totalFld
);
321 DbRetVal
remove(void *fptr
);