📄 catalog.cpp
字号:
if(strcmp(raw->ColumnName,column->ColumnName) == 0){
cell->ColLength = column->StoredLength;
cell->ColType = column->ColType;
cell->PriorLength = len;
switch(column->ColType){
case I:
cell->value.IntValue = raw->value.IntValue;
break;
case F:
cell->value.FloatValue = raw->value.FloatValue;
break;
case C:
cell->value.pCharValue = raw->value.pCharValue;
break;
default:
throw 1010; //Error1010: 错误的数据类型
}
break;
}
raw = raw->next;
}
if(raw == NULL){
cell->ColLength = column->StoredLength;
cell->ColType = column->ColType;
cell->PriorLength = len;
switch(column->ColType){
case I:
cell->value.IntValue = 0;
break;
case F:
cell->value.FloatValue = 0.0;
break;
case C:
cell->value.pCharValue = NULL;
break;
default:
throw 1010; //Error1010: 错误的数据类型
}
}
len += column->StoredLength;
column = (Column_Info*)column->ColumnPtr.FileNext.MemAddr();
if(column != NULL){
cell->next = new Cell_Info;
cell = cell->next;
}
}
}
return;
}
//更新
void HCatalog::Update(TB_Update_Info& info, Condition_Info& index, Rec_Info& record)
{
char temp[289];
sprintf(temp,"%s%s.dbf",CurLocation,CurRelationName);
_M_File CurrentTable = Buffer[temp];
Update_Column* col;
Update_Condition* cond;
col = info.ColumnHead;
cond = info.ConditionHead;
cout<<"text1";
Column_Info* column;
while(col != NULL){
if(!Exist_Column(col->ColumnName))
throw 1008; //Error1008: Column demanded has not existed yet!
column = Find_Column(col->ColumnName);
if(column->IsPrimary == 1)
throw 1018; //Error1018: Update denied on primary key!
if(!Check_Type(column,col->ColType))
throw 1012; //Error1012: Type mismatch!
if(col->ColType == C)
if(!Check_Length(column,&col->value))
throw 1013; //Error1013: Length Invalid for type char!
if(!Check_Value(column,&col->value))
throw 1014; //Error1014: Invalid Value!
col = col->next;
}
cout<<"text1";
Table_Info* table;
table = (Table_Info*)CurrentTable.GetCataPoint().MemAddr();
if(info.ConditionNum != table->KeyAttrNum)
throw 1019; //Error1019: Information Inadequate for selection(Every attribute should be included)!
for(; cond!=NULL; cond=cond->next){
column = this->Find_Column(cond->PrimaryKey);
if(column == NULL)
throw 1007; //Error1007: Primary Key demanded has not existed yet!
if(!this->Check_Key(column))
throw 1011; //Error1011: Not a select based on primary key!
if(!this->Check_Type(column,cond->ColType))
throw 1012; //Error1012: Type mismatch!
if(cond->OperType == BETWEEN){
if(!Check_Key_Validation(cond->ColType,&(cond->max),&(cond->min)))
throw 1020; //Error1020: Result is null!
}
if(cond->ColType == C){ //check if the length is correct if the column is char type
switch(cond->OperType){
case L:
case LE:
if(!Check_Length(column,&(cond->max)))
throw 1013; //Error1013: Length Invalid for type char!
else
break;
case B:
case BE:
if(!Check_Length(column,&(cond->min)))
throw 1013; //Error1013: Length Invalid for type char!
else
break;
case E:
case NE:
case BETWEEN:
if(!Check_Length(column,&(cond->max)) || !Check_Length(column,&(cond->min)))
throw 1013; //Error1013: Length Invalid for type char!
else
break;
default:
throw 1009; //Error1009: Unknown relation operator!
}
}
}
cout<<"text1";
//为 index select的信息
Column_Info* head;
head = (Column_Info*)table->KeyPtr.FileKey.MemAddr();
column = head;
int count = table->KeyAttrNum;
pKey_Attr pkey1,pkey2,pminkey,pmaxkey,pkey3,pkey4;
pminkey = new Key_Attr;
pkey1 = pminkey;
pkey3 = pkey1;
pmaxkey = new Key_Attr;
pkey2 = pmaxkey;
pkey4 = pkey2;
while((column!=NULL) && (count!=0)){
if(column->IsPrimary == 1){
for(cond = info.ConditionHead; cond!=NULL; cond=cond->next){
if(strcmp(cond->PrimaryKey,column->ColumnName)==0){
switch (cond->ColType){
case I:
pkey1->value.IntValue = cond->min.IntValue;
pkey2->value.IntValue = cond->max.IntValue;
break;
case F:
pkey1->value.FloatValue = cond->min.FloatValue;
pkey2->value.FloatValue = cond->max.FloatValue;
break;
case C:
pkey1->value.pCharValue = cond->min.pCharValue;
pkey2->value.pCharValue = cond->max.pCharValue;
break;
default:
throw 1010; //Error1010: 错误的数据类型
}
break;
}
}
if(cond==NULL)
switch(column->ColType){
case I:
pkey1->value.IntValue = 1;
pkey2->value.IntValue = 0;
break;
case F:
pkey1->value.FloatValue = 1.0;
pkey2->value.FloatValue = 0.0;
break;
case C:
strcpy(pkey1->value.pCharValue,"b");
strcpy(pkey2->value.pCharValue,"a");
break;
default:
throw 1010; //Error1010: 错误的数据类型
}
pkey3 = pkey1;
pkey4 = pkey2;
pkey1->next = new Key_Attr;
pkey1 = pkey1->next;
pkey2->next = new Key_Attr;
pkey2 = pkey2->next;
count--;
}
column = (Column_Info*)column->ColumnPtr.FileNext.MemAddr();
}
pkey3->next = NULL;
pkey4->next = NULL;
delete pkey1;
delete pkey2;
index.max = pmaxkey;
index.min = pminkey;
if(info.ConditionHead == NULL)
index.OperType = ALL;
else
index.OperType = info.ConditionHead->OperType;
cout<<"text1";
//为 record update的信息
Cell_Info* cell = new Cell_Info;
Cell_Info* cell1 = cell;
record.head = cell;
record.ColNum = info.ColumnNum;
record.RecordLength = table->RecordLength;
column = head;
int len = 0;
while(column!=NULL){
col = info.ColumnHead;
for(;col!=NULL;col=col->next){
if(strcmp(col->ColumnName,column->ColumnName)==0){
cell->ColLength = column->StoredLength;
cell->ColType = column->ColType;
cell->PriorLength = len;
switch(column->ColType){
case I:
cell->value.IntValue = col->value.IntValue;
break;
case F:
cell->value.FloatValue = col->value.FloatValue;
break;
case C:
cell->value.pCharValue = col->value.pCharValue;
break;
default:
throw 1010; //Error1010:错误的数据类型
}
cell->next = new Cell_Info;
cell1 = cell;
cell = cell->next;
break;
}
}
len += column->StoredLength;
column = (Column_Info*)column->ColumnPtr.FileNext.MemAddr();
}
cell1->next = NULL;
delete cell;
return;
}
//删除
void HCatalog::Delete(TB_Delete_Info& info, Condition_Info& index)
{
char temp[289];
sprintf(temp,"%s%s.dbf",CurLocation,CurRelationName);
_M_File CurrentTable = Buffer[temp];
Delete_Condition* cond=info.head;
Column_Info* column;
Table_Info* table;
table = (Table_Info*)CurrentTable.GetCataPoint().MemAddr();
if(info.ConditionNum != table->KeyAttrNum)
throw 1019; //Error1019: Information Inadequate for selection(Every attribute should be included)!
for(; cond!=NULL; cond=cond->next){
column = this->Find_Column(cond->PrimaryKey);
if(column == NULL)
throw 1007; //Error1007: Primary Key demanded has not existed yet!
if(!this->Check_Key(column))
throw 1011; //Error1011: Not a select based on primary key!
if(!this->Check_Type(column,cond->ColType))
throw 1012; //Error1012: Type mismatch!
if(cond->OperType == BETWEEN){
if(!Check_Key_Validation(cond->ColType,&(cond->max),&(cond->min)))
throw 1020; //Error1020: Result is null!
}
if(cond->ColType == C){
switch(cond->OperType){
case L:
case LE:
if(!Check_Length(column,&(cond->max)))
throw 1013; //Error1013: Length Invalid for type char!
else
break;
case B:
case BE:
if(!Check_Length(column,&(cond->min)))
throw 1013; //Error1013: Length Invalid for type char!
else
break;
case E:
case NE:
case BETWEEN:
if(!Check_Length(column,&(cond->max)) || !Check_Length(column,&(cond->min)))
throw 1013; //Error1013: Length Invalid for type char!
else
break;
default:
throw 1009; //Error1009: 错误的关系运算符
}
}
}
//给index的信息
Column_Info* head;
head = (Column_Info*)table->KeyPtr.FileKey.MemAddr();
column = head;
int count = table->KeyAttrNum;
pKey_Attr pkey1,pkey2,pminkey,pmaxkey,pkey3,pkey4;
pminkey = new Key_Attr;
pkey1 = pminkey;
pkey3 = pkey1;
pmaxkey = new Key_Attr;
pkey2 = pmaxkey;
pkey4 = pkey2;
while((column!=NULL) && (count!=0)){
if(column->IsPrimary == 1){
for(cond = info.head; cond!=NULL; cond=cond->next){
if(strcmp(cond->PrimaryKey,column->ColumnName)==0){
switch (cond->ColType){
case I:
pkey1->value.IntValue = cond->min.IntValue;
pkey2->value.IntValue = cond->max.IntValue;
break;
case F:
pkey1->value.FloatValue = cond->min.FloatValue;
pkey2->value.FloatValue = cond->max.FloatValue;
break;
case C:
pkey1->value.pCharValue = cond->min.pCharValue;
pkey2->value.pCharValue = cond->max.pCharValue;
break;
default:
throw 1010; //Error1010: 错误的数据类型
}
break;
}
}
if(cond==NULL)
switch(column->ColType){
case I:
pkey1->value.IntValue = 1;
pkey2->value.IntValue = 0;
break;
case F:
pkey1->value.FloatValue = 1.0;
pkey2->value.FloatValue = 0.0;
break;
case C:
strcpy(pkey1->value.pCharValue,"b");
strcpy(pkey2->value.pCharValue,"a");
break;
default:
throw 1010; //Error1010: 错误的数据类型
}
pkey3 = pkey1;
pkey4 = pkey2;
pkey1->next = new Key_Attr;
pkey1 = pkey1->next;
pkey2->next = new Key_Attr;
pkey2 = pkey2->next;
count--;
}
column = (Column_Info*)column->ColumnPtr.FileNext.MemAddr();
}
pkey3->next = NULL;
pkey4->next = NULL;
delete pkey1;
delete pkey2;
index.max = pmaxkey;
index.min = pminkey;
if(info.head == NULL)
index.OperType = ALL;
else
index.OperType = info.head->OperType;
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -