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 ***************************************************************************/
16 #include<CatalogTables.h>
21 char ChunkName
[MAX_CHUNKS
][CHUNK_NAME_LEN
]={"UserChunkTableId","LockTableHashBucketId","LockTableMutexId","LockTableId","TransHasTableId","UndoLogTableId","","","","","DatabaseTableId","UserTableId","TableTableId","FieldTableId","AccessTableId","IndexTableId","IndexFieldTableId","ForeignKeyTableId","ForeignKeyFieldTableId"};
24 DbRetVal
CatalogTableTABLE::insert(const char *name
, int id
, size_t size
,
25 int numFlds
, void* chunk
, void *&tptr
, void *vcchunk
)
27 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(TableTableId
);
29 tptr
= tChunk
->allocate(systemDatabase_
, &rv
);
33 "Could not allocate memory for for TABLE catalog table");
36 CTABLE
*tableInfo
= (CTABLE
*)tptr
;
37 strcpy(tableInfo
->tblName_
, name
);
38 tableInfo
->tblID_
= id
;
39 tableInfo
->length_
= size
;
40 tableInfo
->numFlds_
= numFlds
;
41 tableInfo
->numIndexes_
= 0;
42 tableInfo
->chunkPtr_
= chunk
;
43 tableInfo
->varcharChunkPtr_
= vcchunk
;
44 printDebug(DM_SystemDatabase
,"One Row inserted into TABLE %x %s",tptr
, name
);
48 DbRetVal
CatalogTableTABLE::remove(const char *name
, void *&chunk
, void *&tptr
)
50 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(TableTableId
);
51 ChunkIterator iter
= tChunk
->getIterator();
54 while ((data
= iter
.nextElement())!= NULL
)
56 if (0 == strcmp(((CTABLE
*)data
)->tblName_
, name
))
58 //remove this element and store the tblPtr
59 //there will be only one row for this table(Primary key)
61 chunk
= (Chunk
*) ((CTABLE
*)data
)->chunkPtr_
;
67 tChunk
->free(systemDatabase_
, tptr
);
68 printDebug(DM_SystemDatabase
,"One Row deleted from TABLE %x %s",tptr
, name
);
72 printError(ErrNotExists
,"Table %s not exists in TABLE catalog table", name
);
78 DbRetVal
CatalogTableTABLE::getChunkAndTblPtr(const char *name
,
79 void *&chunk
, void *&tptr
, void *&vcchunk
)
81 Chunk
*chk
= systemDatabase_
->getSystemDatabaseChunk(TableTableId
);
82 ChunkIterator iter
= chk
->getIterator();;
83 while (NULL
!= (tptr
= iter
.nextElement()))
85 if (strcmp(((CTABLE
*)tptr
)->tblName_
, name
) == 0)
87 //there will be only one row for this table(Primary key)
88 chunk
= (Chunk
*) ((CTABLE
*)tptr
)->chunkPtr_
;
89 vcchunk
= (Chunk
*) ((CTABLE
*)tptr
)->varcharChunkPtr_
;
93 //table not found in TABLE
98 DbRetVal
CatalogTableTABLE::setChunkPtr(const char *name
, void *firstPage
, void *curPage
)
100 Chunk
*chk
= systemDatabase_
->getSystemDatabaseChunk(TableTableId
);
101 ChunkIterator iter
= chk
->getIterator();;
103 while (NULL
!= (tptr
= iter
.nextElement()))
105 if (strcmp(((CTABLE
*)tptr
)->tblName_
, name
) == 0)
107 //there will be only one row for this table(Primary key)
108 ((Chunk
*)((CTABLE
*)tptr
)->chunkPtr_
)->setFirstPage(firstPage
);
109 ((Chunk
*)((CTABLE
*)tptr
)->chunkPtr_
)->setCurPage(curPage
);
113 //table not found in TABLE
117 List
CatalogTableTABLE::getTableList()
120 Chunk
*chk
= systemDatabase_
->getSystemDatabaseChunk(TableTableId
);
121 ChunkIterator iter
= chk
->getIterator();
123 while (NULL
!= (tptr
= iter
.nextElement()))
125 Identifier
*elem
= new Identifier();
126 strcpy(elem
->name
, ((CTABLE
*)tptr
)->tblName_
);
127 tableList
.append(elem
);
132 DbRetVal
CatalogTableFIELD::insert(FieldIterator
&iter
, int tblID
, void *tptr
)
134 Chunk
*fChunk
= systemDatabase_
->getSystemDatabaseChunk(FieldTableId
);
136 while (iter
.hasElement())
138 void *fptr
= fChunk
->allocate(systemDatabase_
, &rv
);
142 "Could not allocate for FIELD catalog table");
145 CFIELD
*fldInfo
= (CFIELD
*)fptr
;
146 FieldDef
*fDef
= iter
.nextElement();
147 strcpy(fldInfo
->fldName_
, fDef
->fldName_
);
148 fldInfo
->tblID_
= tblID
;
149 fldInfo
->tblPtr_
= tptr
;
150 fldInfo
->type_
= fDef
->type_
;
151 fldInfo
->length_
= fDef
->length_
;
152 fldInfo
->offset_
= fDef
->offset_
;
153 os::memcpy(fldInfo
->defaultValueBuf_
, fDef
->defaultValueBuf_
,
154 DEFAULT_VALUE_BUF_LENGTH
);
155 fldInfo
->isNull_
= fDef
->isNull_
;
156 fldInfo
->isPrimary_
= fDef
->isPrimary_
;
157 fldInfo
->isUnique_
= fDef
->isUnique_
;
158 fldInfo
->isDefault_
= fDef
->isDefault_
;
159 fldInfo
->isAutoIncrement_
= fDef
->isAutoIncrement_
;
160 fldInfo
->autoVal_
= 0;
161 fldInfo
->width_
= 0; //TODO
162 fldInfo
->scale_
= 0; //TODO
163 printDebug(DM_SystemDatabase
,"One Row inserted into FIELD %x %s",fldInfo
, fDef
->fldName_
);
169 DbRetVal
CatalogTableFIELD::remove(void *tptr
)
171 Chunk
*fChunk
= systemDatabase_
->getSystemDatabaseChunk(FieldTableId
);
172 ChunkIterator fIter
= fChunk
->getIterator();
174 while ((data
= fIter
.nextElement())!= NULL
)
176 if (((CFIELD
*)data
)->tblPtr_
== tptr
)
178 //remove this element
179 fChunk
->free(systemDatabase_
, data
);
180 printDebug(DM_SystemDatabase
,"One Row deleted from FIELD %x",data
);
186 void *CatalogTableFIELD::getFieldInfo(void* tptr
, FieldList
&list
)
188 Chunk
*fChunk
= systemDatabase_
->getSystemDatabaseChunk(FieldTableId
);
189 ChunkIterator fIter
= fChunk
->getIterator();;
192 while (NULL
!= (data
= fIter
.nextElement()))
194 if (((CFIELD
*)data
)->tblPtr_
== tptr
)
196 //add the information to the field list
197 CFIELD
*fTuple
= (CFIELD
*)data
;
199 strcpy(fldDef
.fldName_
, fTuple
->fldName_
);
200 fldDef
.fldName_
[IDENTIFIER_LENGTH
] = '\0';
201 fldDef
.type_
= fTuple
->type_
;
202 fldDef
.length_
= fTuple
->length_
;
203 fldDef
.offset_
= fTuple
->offset_
;
204 fldDef
.isDefault_
= fTuple
->isDefault_
;
205 os::memcpy(fldDef
.defaultValueBuf_
, fTuple
->defaultValueBuf_
,
206 DEFAULT_VALUE_BUF_LENGTH
);
207 fldDef
.isNull_
= fTuple
->isNull_
;
208 fldDef
.isUnique_
= fTuple
->isUnique_
;
209 fldDef
.isPrimary_
= fTuple
->isPrimary_
;
210 fldDef
.isAutoIncrement_
= fTuple
->isAutoIncrement_
;
211 if(fTuple
->isAutoIncrement_
){
212 ptrToAutoVal
= &fTuple
->autoVal_
;
213 //os::memcpy(fldDef.autoVal_, fTuple->autoVal_,);
221 DbRetVal
CatalogTableFIELD::getFieldPtrs(FieldNameList
&fldList
,void *tptr
, char **&fptr
)
223 Chunk
*fChunk
= systemDatabase_
->getSystemDatabaseChunk(FieldTableId
);
230 while (NULL
!= (fName
= fldList
.nextFieldName()))
232 ChunkIterator fIter
= fChunk
->getIterator();
234 while (NULL
!= (data
= fIter
.nextElement()))
236 if (((CFIELD
*)data
)->tblPtr_
== tptr
)
238 if(0 == strcmp((char*)((CFIELD
*)data
)->fldName_
, fName
))
241 //if (! ((FIELD*)data)->isNull_) rv = ErrBadCall;
242 fptr
[i
++] = (char*) data
;
249 printError(ErrNotFound
,
250 "No entries found in FIELD catalog table for the table specified");
257 DbRetVal
CatalogTableINDEX::insert(const char *name
, void *tptr
, int numFlds
, bool isUnique
,
258 void* chunk
, int bucketSize
, void *hChunk
, void *&tupleptr
)
260 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(IndexTableId
);
261 ChunkIterator iter
= tChunk
->getIterator();
263 //Checking for index having same name, proceed further only
264 //if no such indexes are
266 while ((data
= iter
.nextElement())!= NULL
)
268 if (0 == strcmp(((CINDEX
*)data
)->indName_
, name
))
270 printError(ErrAlready
, "Index with name \'%s\' already exists "
271 "on the table \'%s\'.", name
, ((CTABLE
*)tptr
)->tblName_
);
278 tupleptr
= tChunk
->allocate(systemDatabase_
, &rv
);
279 if (NULL
== tupleptr
)
282 "Could not allocate for INDEX catalog table");
285 CINDEX
*indexInfo
= (CINDEX
*)tupleptr
;
286 strcpy(indexInfo
->indName_
, name
);
287 indexInfo
->tblID_
= -1; //Not used currently
288 indexInfo
->tblPtr_
= tptr
;
289 indexInfo
->numFlds_
= numFlds
;
291 indexInfo
->indexType_
= treeIndex
;
293 indexInfo
->indexType_
= hashIndex
;
294 indexInfo
->chunkPtr_
= chunk
;
295 indexInfo
->hashNodeChunk_
= hChunk
;
296 indexInfo
->noOfBuckets_
= bucketSize
;
297 indexInfo
->isUnique_
= isUnique
;
298 indexInfo
->fstIndFld_
=NULL
;
299 printDebug(DM_SystemDatabase
,"One Row inserted into INDEX %x %s",tupleptr
, name
);
303 DbRetVal
CatalogTableINDEX::remove(const char *name
, void *&chunk
, void *&hchunk
, void *&iptr
)
305 Chunk
*fChunk
= systemDatabase_
->getSystemDatabaseChunk(IndexTableId
);
306 ChunkIterator iter
= fChunk
->getIterator();
309 while ((data
= iter
.nextElement())!= NULL
)
311 if (0 == strcmp(((CINDEX
*)data
)->indName_
, name
))
313 //remove this element and store the tuple ptr
314 //there will be only one row for this table(Primary key)
315 chunk
= (Chunk
*) ((CINDEX
*)data
)->chunkPtr_
;
316 hchunk
= (Chunk
*) ((CINDEX
*)data
)->hashNodeChunk_
;
323 fChunk
->free(systemDatabase_
, iptr
);
324 printDebug(DM_SystemDatabase
,"One Row deleted from INDEX %x %s",iptr
, name
);
328 printError(ErrNotExists
,"Index %s not exists in INDEX catalog table", name
);
333 DbRetVal
CatalogTableINDEX::get(const char *name
, void *&chunk
, void *&hchunk
, void *&iptr
)
335 Chunk
*fChunk
= systemDatabase_
->getSystemDatabaseChunk(IndexTableId
);
336 ChunkIterator iter
= fChunk
->getIterator();
339 while ((data
= iter
.nextElement())!= NULL
)
341 if (0 == strcmp(((CINDEX
*)data
)->indName_
, name
))
343 //remove this element and store the tuple ptr
344 //there will be only one row for this table(Primary key)
345 chunk
= (Chunk
*) ((CINDEX
*)data
)->chunkPtr_
;
346 hchunk
= (Chunk
*) ((CINDEX
*)data
)->hashNodeChunk_
;
353 printError(ErrNotExists
,"Index %s not exists in INDEX catalog table", name
);
359 DbRetVal
CatalogTableINDEX::setChunkPtr(const char *name
, ObjectType type
, void *bChunk
, void *firstPage
, void *curPage
)
361 Chunk
*fChunk
= systemDatabase_
->getSystemDatabaseChunk(IndexTableId
);
362 ChunkIterator iter
= fChunk
->getIterator();
365 while ((data
= iter
.nextElement())!= NULL
)
367 if (0 == strcmp(((CINDEX
*)data
)->indName_
, name
))
369 //remove this element and store the tuple ptr
370 //there will be only one row for this table(Primary key)
372 ((Chunk
*) ((CINDEX
*)data
)->chunkPtr_
)->setFirstPage(bChunk
);
373 ((Chunk
*) ((CINDEX
*)data
)->chunkPtr_
)->setCurPage(bChunk
);
374 ((Chunk
*)((CINDEX
*)data
)->hashNodeChunk_
)->setFirstPage(firstPage
);
375 ((Chunk
*)((CINDEX
*)data
)->hashNodeChunk_
)->setCurPage(curPage
);
376 } else if (type
== tIdx
) {
377 ((Chunk
*) ((CINDEX
*)data
)->chunkPtr_
)->setFirstPage(firstPage
);
378 ((Chunk
*) ((CINDEX
*)data
)->chunkPtr_
)->setCurPage(curPage
);
379 ((CINDEX
*)data
)->hashNodeChunk_
= bChunk
;
387 int CatalogTableINDEX::getNumIndexes(void *tptr
)
389 Chunk
*fChunk
= systemDatabase_
->getSystemDatabaseChunk(IndexTableId
);
390 ChunkIterator iter
= fChunk
->getIterator();
393 while (NULL
!= (iptr
= iter
.nextElement()))
395 if (((CINDEX
*)iptr
)->tblPtr_
== tptr
) numIndex
++;
400 ListIterator
CatalogTableINDEXFIELD::getIndexListIterater(char *name
)
403 Chunk
*chunk
=systemDatabase_
->getSystemDatabaseChunk(IndexFieldTableId
);
404 ChunkIterator ifIter
= chunk
->getIterator();
406 while ((data
= ifIter
.nextElement())!= NULL
)
408 IndexInfoForDriver
*idxInfo
= new IndexInfoForDriver();
409 if(strcmp( name
,((CTABLE
*)(((CINDEXFIELD
*)data
)->tablePtr
))->tblName_
) == 0)
411 strcpy(idxInfo
->indexName
,((CINDEX
*)(((CINDEXFIELD
*)data
)->indexPtr
))->indName_
);
412 strcpy(idxInfo
->tableName
,((CTABLE
*)(((CINDEXFIELD
*)data
)->tablePtr
))->tblName_
);
413 strcpy(idxInfo
->fieldName
,((CFIELD
*)(((CINDEXFIELD
*)data
)->fieldPtr
))->fldName_
);
414 idxInfo
->type
= ((CINDEX
*)(((CINDEXFIELD
*)data
)->indexPtr
))->indexType_
;
415 idxInfo
->isUnique
= ((CINDEX
*)(((CINDEXFIELD
*)data
)->indexPtr
))->isUnique_
;
416 idxInfo
->isPrimary
= ((CFIELD
*)(((CINDEXFIELD
*)data
)->fieldPtr
))->isPrimary_
;
417 indexList
.append(idxInfo
);
420 return indexList
.getIterator();
423 char* CatalogTableINDEX::getIndexName(void *tptr
, int position
)
425 if (position
== 0) return NULL
;
426 Chunk
*fChunk
= systemDatabase_
->getSystemDatabaseChunk(IndexTableId
);
427 ChunkIterator iter
= fChunk
->getIterator();
431 while (NULL
!= (iptr
= iter
.nextElement()))
433 if (((CINDEX
*)iptr
)->tblPtr_
== tptr
) curPos
++;
434 if ( curPos
== position
) return ((CINDEX
*)iptr
)->indName_
;
440 void CatalogTableINDEX::getIndexPtrs(void *tptr
, char **&array
)
443 Chunk
*fChunk
= systemDatabase_
->getSystemDatabaseChunk(IndexTableId
);
444 ChunkIterator iter
= fChunk
->getIterator();
446 while (NULL
!= (iptr
= iter
.nextElement()))
448 if (((CINDEX
*)iptr
)->tblPtr_
== tptr
)
450 array
[i
++] = (char*) iptr
;
456 ChunkIterator
CatalogTableINDEX::getIterator(void *iptr
)
458 CINDEX
*index
= (CINDEX
*)iptr
;
459 return ((Chunk
*)index
->chunkPtr_
)->getIterator();
463 int CatalogTableINDEX::getNoOfBuckets(void *iptr
)
465 CINDEX
*index
= (CINDEX
*)iptr
;
466 return index
->noOfBuckets_
;
469 int CatalogTableINDEX::getUnique(void *iptr
)
471 CINDEX
*index
= (CINDEX
*)iptr
;
472 return index
->isUnique_
;
474 IndexType
CatalogTableINDEX::getType(void *iptr
)
476 CINDEX
*index
= (CINDEX
*)iptr
;
477 return index
->indexType_
;
479 char* CatalogTableINDEX::getName(void *iptr
)
481 CINDEX
*index
= (CINDEX
*)iptr
;
482 return index
->indName_
;
484 int CatalogTableINDEX::getOffsetOfFirstField(void *iptr
)
486 CINDEX
*index
= (CINDEX
*)iptr
;
487 return ((CFIELD
*)(((CINDEXFIELD
*)(index
->fstIndFld_
))->fieldPtr
))->offset_
;
489 DbRetVal
CatalogTableINDEXFIELD::insert(FieldNameList
&fldList
, void *indexPtr
,
490 void *tblPtr
, char **&fptr
)
494 tChunk
= systemDatabase_
->getSystemDatabaseChunk(IndexTableId
);
495 ChunkIterator iter
= tChunk
->getIterator();
496 CINDEXFIELD
*fInd
=NULL
;
500 while ((data
= iter
.nextElement())!= NULL
)
502 if ((((CINDEX
*)data
)->tblPtr_
==tblPtr
)
503 && (((CINDEX
*)indexPtr
)->numFlds_
== ((CINDEX
*)data
)->numFlds_
)
504 && (((CINDEX
*)indexPtr
)->indexType_
==((CINDEX
*)data
)->indexType_
)
505 && (data
!= indexPtr
) )
508 while (NULL
!= (fName
= fldList
.nextFieldName()))
511 fInd
=(CINDEXFIELD
*)((CINDEX
*)data
)->fstIndFld_
;
514 if (0 == strcmp(((CFIELD
*) fInd
->fieldPtr
)->fldName_
, fName
))
525 printError(ErrAlready
, "Index on this field already exists on table \'%s\' by name \'%s\'", ((CTABLE
*)tblPtr
)->tblName_
, ((CINDEX
*)data
)->indName_
);
532 tChunk
= systemDatabase_
->getSystemDatabaseChunk(IndexFieldTableId
);
535 while (NULL
!= (fName
= fldList
.nextFieldName()))
538 fInd
=(CINDEXFIELD
*)((CINDEX
*)indexPtr
)->fstIndFld_
;
541 if (0 == strcmp(((CFIELD
*) fInd
->fieldPtr
)->fldName_
, fName
))
543 printError(ErrAlready
,"Composite Index Can't be created with same Name");
544 fInd
=(CINDEXFIELD
*)((CINDEX
*)indexPtr
)->fstIndFld_
;
550 tChunk
->free(systemDatabase_
,fldI
);
556 void *fieldptr
= tChunk
->allocate(systemDatabase_
, &rv
);
557 if (NULL
== fieldptr
)
559 printError(rv
, "Could not allocate for USER catalog table");
562 CINDEXFIELD
*fldInfo
= (CINDEXFIELD
*)fieldptr
;
563 fldInfo
->tablePtr
= tblPtr
;
564 fldInfo
->fieldPtr
= (CFIELD
*)fptr
[i
++];
565 fldInfo
->indexPtr
= indexPtr
;
566 fldInfo
->next
=(CINDEXFIELD
*)((CINDEX
*)indexPtr
)->fstIndFld_
;
567 ((CINDEX
*)indexPtr
)->fstIndFld_
=fldInfo
;
568 printDebug(DM_SystemDatabase
,"One Row inserted into INDEXFIELD %x", fldInfo
);
573 DbRetVal
CatalogTableINDEXFIELD::remove(void *iptr
)
576 fChunk
= systemDatabase_
->getSystemDatabaseChunk(IndexFieldTableId
);
577 ChunkIterator fIter
= fChunk
->getIterator();
579 while ((data
= fIter
.nextElement())!= NULL
)
581 if (((CINDEXFIELD
*)data
)->indexPtr
== iptr
)
583 //remove this element
584 if(((CFIELD
*)((CINDEXFIELD
*)data
)->fieldPtr
)->isUnique_
) ((CFIELD
*)((CINDEXFIELD
*)data
)->fieldPtr
)->isUnique_
= false;
585 fChunk
->free(systemDatabase_
, data
);
586 printDebug(DM_SystemDatabase
,"One Row deleted from INDEXFIELD %x", data
);
592 DbRetVal
CatalogTableINDEXFIELD::getFieldNameAndType(void *index
,
593 char *&name
, DataType
&type
)
596 ifChunk
= systemDatabase_
->getSystemDatabaseChunk(IndexFieldTableId
);
597 ChunkIterator ifIter
= ifChunk
->getIterator();
599 while ((data
= ifIter
.nextElement())!= NULL
)
601 if (((CINDEXFIELD
*)data
)->indexPtr
== index
)
603 //store the field name
604 name
= ((CFIELD
*)(((CINDEXFIELD
*)data
)->fieldPtr
))->fldName_
;
605 type
= ((CFIELD
*)(((CINDEXFIELD
*)data
)->fieldPtr
))->type_
;
609 printError(ErrNotExists
,"Index %x not exists in catalog table", index
);
613 DbRetVal
CatalogTableINDEXFIELD::getFieldInfo(void *index
, FieldList
&list
)
616 ifChunk
= systemDatabase_
->getSystemDatabaseChunk(IndexFieldTableId
);
617 ChunkIterator ifIter
= ifChunk
->getIterator();
620 while ((data
= ifIter
.nextElement())!= NULL
)
622 if (((CINDEXFIELD
*)data
)->indexPtr
== index
)
624 //add the information to the field list
625 CFIELD
*fTuple
= (CFIELD
*)(((CINDEXFIELD
*)data
)->fieldPtr
);
627 strcpy(fldDef
.fldName_
, fTuple
->fldName_
);
628 fldDef
.fldName_
[IDENTIFIER_LENGTH
] = '\0';
629 fldDef
.type_
= fTuple
->type_
;
630 fldDef
.length_
= fTuple
->length_
;
631 fldDef
.offset_
= fTuple
->offset_
;
632 fldDef
.isDefault_
= fTuple
->isDefault_
;
633 os::memcpy(fldDef
.defaultValueBuf_
, fTuple
->defaultValueBuf_
,
634 DEFAULT_VALUE_BUF_LENGTH
);
635 fldDef
.isNull_
= fTuple
->isNull_
;
636 fldDef
.isUnique_
= fTuple
->isUnique_
;
637 fldDef
.isPrimary_
= fTuple
->isPrimary_
;
643 printError(ErrNotExists
,"Index %x not exists in catalog table", index
);
649 void CatalogTableINDEXFIELD::printAllIndex()
651 Chunk
*chunk
=systemDatabase_
->getSystemDatabaseChunk(IndexFieldTableId
);
652 ChunkIterator ifIter
= chunk
->getIterator();
654 char indexName
[IDENTIFIER_LENGTH
] = {'\0'};
655 while ((data
= ifIter
.nextElement())!= NULL
)
657 if(strcmp(indexName
,((CINDEX
*)(((CINDEXFIELD
*)data
)->indexPtr
))->indName_
)!=0)
659 printf(" <Index Name> %s </Index Name> \n",((CINDEX
*)(((CINDEXFIELD
*)data
)->indexPtr
))->indName_
);
660 if(0==((CINDEX
*)(((CINDEXFIELD
*)data
)->indexPtr
))->indexType_
)
661 printf(" <Index Type> Hash Index </Index Type> \n");
663 printf(" <Index Type> Tree Index </Index Type> \n");
664 printf(" <Table Name> %s </Table Name> \n",((CTABLE
*)(((CINDEXFIELD
*)data
)->tablePtr
))->tblName_
);
665 printf(" <Field Name> %s </Field Name> \n",((CFIELD
*)(((CINDEXFIELD
*)data
)->fieldPtr
))->fldName_
);
669 printf(" <Field Name> %s </Field Name> \n",((CFIELD
*)(((CINDEXFIELD
*)data
)->fieldPtr
))->fldName_
);
671 strcpy(indexName
,((CINDEX
*)(((CINDEXFIELD
*)data
)->indexPtr
))->indName_
);
675 List
CatalogTableUSER::getUserList()
678 Chunk
*chk
= systemDatabase_
->getSystemDatabaseChunk(UserTableId
);
679 ChunkIterator iter
= chk
->getIterator();
681 while (NULL
!= (tptr
= iter
.nextElement()))
683 Identifier
*elem
= new Identifier();
684 strcpy(elem
->name
, ((CUSER
*)tptr
)->userName_
);
685 userList
.append(elem
);
691 DbRetVal
CatalogTableUSER::insert(const char *name
, const char *pass
)
693 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(UserTableId
);
695 ChunkIterator iter
= tChunk
->getIterator();
697 while ((data
= iter
.nextElement())!= NULL
)
699 if (0 == strcmp(((CUSER
*)data
)->userName_
, name
))
701 printError(ErrAlready
, "User with name \'%s\' already exists ", name
);
706 CUSER
*usrInfo
= (CUSER
*)tChunk
->allocate(systemDatabase_
, &rv
);
710 "Could not allocate for USER catalog table");
713 strcpy(usrInfo
->userName_
, name
);
714 strcpy(usrInfo
->password_
, pass
);
715 //strcpy(usrInfo->password_, os::encrypt(pass, "A0"));
720 DbRetVal
CatalogTableUSER::authenticate(const char *name
, const char *pass
,
721 bool &isAuthenticated
, bool &isDba
)
723 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(UserTableId
);
724 ChunkIterator iter
= tChunk
->getIterator();
726 while (NULL
!= (data
= iter
.nextElement()))
728 if (strcmp(((CUSER
*)data
)->userName_
, name
) == 0)
730 //verify the password
731 //char * enpass = os::encrypt(pass,"A0");
732 char * enpass
= (char*) pass
;
733 if (0 == strcmp(enpass
, ((CUSER
*)data
)->password_
))
735 isAuthenticated
= true;
736 if (0 == strcmp(((CUSER
*)data
)->userName_
, DBAUSER
))
737 isDba
= true; else isDba
= false;
742 isAuthenticated
= false;
746 DbRetVal
CatalogTableUSER::remove(const char *name
)
748 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(UserTableId
);
749 ChunkIterator iter
= tChunk
->getIterator();
751 while ((data
= iter
.nextElement())!= NULL
)
753 if (strcmp(((CUSER
*)data
)->userName_
, name
) == 0)
755 //remove this element
756 tChunk
->free(systemDatabase_
, data
);
760 printError(ErrNotExists
,"User %s not exists in catalog table", name
);
764 DbRetVal
CatalogTableUSER::changePass(const char *name
, const char *pass
)
766 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(UserTableId
);
767 ChunkIterator iter
= tChunk
->getIterator();
769 while (NULL
!= (data
= iter
.nextElement()))
771 if (strcmp(((CUSER
*)data
)->userName_
, name
) == 0)
773 //change the password
774 strcpy(((CUSER
*)data
)->password_
,pass
);// os::encrypt(pass, "A0"));
778 printError(ErrNotExists
,"User %s not exists in catalog table", name
);
782 DbRetVal
CatalogTableFK::insert(char *name
, void *tptr
, void *tPkptr
)
784 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(ForeignKeyTableId
);
785 ChunkIterator iter
= tChunk
->getIterator();
787 while ((data
= iter
.nextElement())!= NULL
)
789 if (0 == strcmp(((CFK
*)data
)->fkName_
, name
))
791 printError(ErrAlready
, "Index with name \'%s\' already exists "
792 "on the table \'%s\'.", name
, ((CTABLE
*)tptr
)->tblName_
);
799 void *fkptr
= tChunk
->allocate(systemDatabase_
, &rv
);
802 printError(rv
, "Could not allocate for FK catalog table");
805 CFK
*fkTblInfo
= (CFK
*)fkptr
;
806 strcpy(fkTblInfo
->fkName_
, name
);
807 fkTblInfo
->fkTblPtr_
= tptr
;
808 fkTblInfo
->pkTblPtr_
= tPkptr
;
809 printDebug(DM_SystemDatabase
,"One Row inserted into FK %x %s",fkptr
, name
);
813 DbRetVal
CatalogTableFKFIELD::insert(char *cFKName
, char **fkFldPtrs
, char **pkFldPtrs
,int totalFld
)
815 Chunk
*tChunk
= NULL
;
816 tChunk
= systemDatabase_
->getSystemDatabaseChunk(ForeignKeyTableId
);
817 ChunkIterator iter
= tChunk
->getIterator();
819 while ((data
= iter
.nextElement())!= NULL
)
821 if (0 == strcmp(((CFK
*)data
)->fkName_
, cFKName
))
826 tChunk
= systemDatabase_
->getSystemDatabaseChunk(ForeignKeyFieldTableId
);
831 void *fieldptr
= tChunk
->allocate(systemDatabase_
, &rv
);
832 if (NULL
== fieldptr
)
834 printError(rv
, "Could not allocate for USER catalog table");
837 CFKFIELD
*fldInfo
= (CFKFIELD
*)fieldptr
;
838 fldInfo
->fkPtr_
= data
;
839 fldInfo
->pfFldPtr_
= (CFIELD
*)pkFldPtrs
[i
];
840 fldInfo
->fkFldPtr_
= (CFIELD
*)fkFldPtrs
[i
++];
841 //printDebug(DM_TEST,"TYPE %d\n",((CFIELD*)fldInfo->pfFldPtr_)->type_);
842 //printDebug(DM_TEST,"FK name %s\n",((CFIELD*)fldInfo->fkFldPtr_)->fldName_);
843 if(!(((CFIELD
*)fldInfo
->pfFldPtr_
)->isUnique_
) || !(((CFIELD
*)fldInfo
->pfFldPtr_
)->isNull_
))
845 printError(ErrSysInternal
,"Parent Table field should have primary key field ");
846 tChunk
->free(systemDatabase_
,fieldptr
);
847 return ErrSysInternal
;
849 if(((CFIELD
*)fldInfo
->pfFldPtr_
)->type_
!=((CFIELD
*)fldInfo
->fkFldPtr_
)->type_
)
851 printError(ErrSysInternal
,"Type Missmatch in both PK field and FK field ");
852 tChunk
->free(systemDatabase_
,fieldptr
);
853 return ErrSysInternal
;
855 printDebug(DM_SystemDatabase
,"One Row inserted into FKFIELD %x", fldInfo
);
859 DbRetVal
CatalogTableFK::remove(void *ctptr
)
861 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(ForeignKeyTableId
);
862 ChunkIterator iter
= tChunk
->getIterator();
864 while ((data
= iter
.nextElement())!= NULL
)
868 tChunk
->free(systemDatabase_
,data
);
869 printDebug(DM_SystemDatabase
,"One Row deleted from FKFIELD %x", data
);
876 DbRetVal
CatalogTableFKFIELD::remove(void *cFKfld
)
878 Chunk
*fChunk
= NULL
;
879 fChunk
= systemDatabase_
->getSystemDatabaseChunk(ForeignKeyFieldTableId
);
880 ChunkIterator iter
= fChunk
->getIterator();
882 while ((data
= iter
.nextElement())!= NULL
)
884 if (((CFKFIELD
*)data
)->fkPtr_
== cFKfld
)
886 fChunk
->free(systemDatabase_
, data
);
887 printDebug(DM_SystemDatabase
,"One Row deleted from CFKFIELD %x", data
);
892 void *CatalogTableFK::getFkCTable(void *ctptr
)
894 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(ForeignKeyTableId
);
895 ChunkIterator iter
= tChunk
->getIterator();
897 while ((data
= iter
.nextElement())!= NULL
)
899 if (((CFK
*)data
)->fkTblPtr_
== ctptr
)
907 int CatalogTableFK::getNumFkTable(void *ctptr
)
909 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(ForeignKeyTableId
);
910 ChunkIterator iter
= tChunk
->getIterator();
913 while ((data
= iter
.nextElement())!= NULL
)
915 if (((CFK
*)data
)->pkTblPtr_
== ctptr
)
923 bool CatalogTableFK::isFkTable(void *ctptr
)
925 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(ForeignKeyTableId
);
926 ChunkIterator iter
= tChunk
->getIterator();
929 while ((data
= iter
.nextElement())!= NULL
)
931 if (((CFK
*)data
)->fkTblPtr_
== ctptr
)
938 int CatalogTableFK::getNoOfFkTable(void *ctptr
)
940 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(ForeignKeyTableId
);
941 ChunkIterator iter
= tChunk
->getIterator();
944 while ((data
= iter
.nextElement())!= NULL
)
946 if (((CFK
*)data
)->pkTblPtr_
== ctptr
)
954 int CatalogTableFK::getNoOfPkTable(void *ctptr
)
956 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(ForeignKeyTableId
);
957 ChunkIterator iter
= tChunk
->getIterator();
960 while ((data
= iter
.nextElement())!= NULL
)
962 if (((CFK
*)data
)->fkTblPtr_
== ctptr
)
970 void CatalogTableFK::getPkTableName(void *ctptr
,char **&array
)
972 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(ForeignKeyTableId
);
973 ChunkIterator iter
= tChunk
->getIterator();
976 while ((data
= iter
.nextElement())!= NULL
)
978 if (((CFK
*)data
)->fkTblPtr_
== ctptr
)
980 array
[i
++] = ((CTABLE
*)((CFK
*)data
)->pkTblPtr_
)->tblName_
;
984 void CatalogTableFK::getFkTableName(void *ctptr
,char **&array
)
986 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(ForeignKeyTableId
);
987 ChunkIterator iter
= tChunk
->getIterator();
990 while ((data
= iter
.nextElement())!= NULL
)
992 if (((CFK
*)data
)->pkTblPtr_
== ctptr
)
994 array
[i
++] = ((CTABLE
*)((CFK
*)data
)->fkTblPtr_
)->tblName_
;
1000 DbRetVal
CatalogTableFK::getPkFkFieldInfo(void *cpkptr
, void *cfkptr
, FieldNameList
&pklist
,FieldNameList
&fklist
)
1002 Chunk
*tChunk
= systemDatabase_
->getSystemDatabaseChunk(ForeignKeyTableId
);
1003 ChunkIterator iter
= tChunk
->getIterator();
1005 while ((data
= iter
.nextElement())!= NULL
)
1007 if (((CFK
*)data
)->pkTblPtr_
== cpkptr
&& ((CFK
*)data
)->fkTblPtr_
== cfkptr
)
1014 printError(ErrNotExists
,"Foreign Key field CFK not found");
1015 return ErrNotExists
;
1017 Chunk
*fChunk
= systemDatabase_
->getSystemDatabaseChunk(ForeignKeyFieldTableId
);
1018 iter
= fChunk
->getIterator();
1020 while ((fdata
= iter
.nextElement())!= NULL
)
1022 if (((CFKFIELD
*)fdata
)->fkPtr_
==data
)
1024 //printDebug(DM_TEST,"PK Field name %s\n",((CFIELD*)((CFKFIELD*)fdata)->pfFldPtr_)->fldName_);
1025 //printDebug(DM_TEST,"FK Field name %s\n",((CFIELD*)((CFKFIELD*)fdata)->fkFldPtr_)->fldName_);
1026 pklist
.append(((CFIELD
*)((CFKFIELD
*)fdata
)->pfFldPtr_
)->fldName_
);
1027 fklist
.append(((CFIELD
*)((CFKFIELD
*)fdata
)->fkFldPtr_
)->fldName_
);