BadgerDB
|
00001 00008 #include <cstring> 00009 #include "catalog.h" 00010 #include "updates.h" 00011 #include "index.h" 00012 #include "utility.h" 00013 #include "exceptions/end_of_file_exception.h" 00014 #include "exceptions/no_more_records_exception.h" 00015 #include "exceptions/bad_param_exception.h" 00016 00017 extern badgerdb::BufMgr *bufMgr; 00018 00019 namespace badgerdb 00020 { 00021 00022 void Updates::Insert(const std::string &relation, int attrCnt, const attrInfo attrList[]) 00023 { 00024 int i; 00025 /*for(i = 0 ; i < attrCnt; i++){ 00026 std::cout<<"\nattrList["<<i<<"]"; 00027 Helpers::printAttrInfo(&attrList[i]); 00028 } 00029 std::cout<<"\nRelation: "<<relation; 00030 */ 00031 RelDesc rd; 00032 AttrDesc *attrs; 00033 int attrCntReal; 00034 std::string s1, s2; 00035 relCat->getInfo(relation, rd); 00036 // get attribute data 00037 attrCat->getRelInfo(rd.relName, attrCntReal, attrs); 00038 if(attrCntReal != attrCnt){//checks to make sure correct number of attributes 00039 return; 00040 } 00041 int projToAttrMap[attrCntReal]; 00042 for(i = 0; i < attrCntReal; i++){//gets correct order of attributes, 00043 00044 s1 = attrList[i].attrName; 00045 for(int j = 0; j < attrCntReal; j++){ 00046 s2 = attrs[j].attrName; 00047 if(s1.compare(s2) == 0){ 00048 projToAttrMap[i] =j; 00049 break; 00050 } 00051 } 00052 } 00053 00054 int length; 00055 Datatype type; 00056 RecordId insertRecId; 00057 00058 00059 for(i = 0; i< attrCntReal; i++){ 00060 if(attrs[i].indexed ==1){//if attribute is indexed, create index object(should already be created) 00061 Index attrobject(rd.relName, attrs[i].attrOffset, length , type, 1, bufMgr); 00062 attrobject.insertEntry(attrList[i].attrValue, insertRecId); 00063 } 00064 00065 } 00066 00067 00068 00069 00070 00071 } 00072 00073 }