?? catalog.cpp
字號:
}//end while
}//end if
//if there is default column
else{
column = head;
len = 0;
while(column!=NULL){
raw = info.head;
while(raw != NULL){
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: Unknown type!
}
break;
}
raw = raw->next;
}//end inner while
//give the column that user don't default value
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: Unknown type!
}
}//end if
len += column->StoredLength;
column = (Column_Info*)column->ColumnPtr.FileNext.MemAddr();
if(column != NULL){
cell->next = new Cell_Info;
cell = cell->next;
}
}//end outer while
}//end else
return;
}
//---------------------------------------------------------------------------------------
//update
void HCatalog::Update(TB_Update_Info& info, Condition_Info& index, Rec_Info& record)
{
//locate current table
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;
Column_Info* column;
//check validation
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;
}
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!
}//end switch
}//end if
}//end for
//form information for 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; //min
pkey3 = pkey1; //save pkey1
pmaxkey = new Key_Attr;
pkey2 = pmaxkey; //max
pkey4 = pkey2; //save pkey2
//organize information
while((column!=NULL) && (count!=0)){
//if this column is primary key
if(column->IsPrimary == 1){
//find the corresponding column
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: Unknown type!
}//end switch
break;
}//end if
}//end for
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: Unknown type!
}//end switch
pkey3 = pkey1;
pkey4 = pkey2;
pkey1->next = new Key_Attr;
pkey1 = pkey1->next;
pkey2->next = new Key_Attr;
pkey2 = pkey2->next;
count--;
}//end if
column = (Column_Info*)column->ColumnPtr.FileNext.MemAddr();
}//end while
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;
//form information for 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; //for prior length
while(column!=NULL){
col = info.ColumnHead;
//find the corresponding column
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: Unknown type!
}
cell->next = new Cell_Info;
cell1 = cell;
cell = cell->next;
break;
}
}
len += column->StoredLength;
column = (Column_Info*)column->ColumnPtr.FileNext.MemAddr();
}//end while
cell1->next = NULL;
delete cell;
return;
}
//----------------------------------------------------------------------------------------------
//delete
void HCatalog::Delete(TB_Delete_Info& info, Condition_Info& index)
{
//locate current table
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();
//check validation
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!
}//end switch
}//end if
}//end for
//organize information for 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; //min
pkey3 = pkey1; //save pkey1
pmaxkey = new Key_Attr;
pkey2 = pmaxkey; //max
pkey4 = pkey2; //save pkey2
//organzie information
while((column!=NULL) && (count!=0)){
//if this column is primary key
if(column->IsPrimary == 1){
//find the corresponding column
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: Unknown type!
}//end switch
break;
}//end if
}//end for
//if no constraint
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: Unknown type!
}//end switch
pkey3 = pkey1;
pkey4 = pkey2;
pkey1->next = new Key_Attr;
pkey1 = pkey1->next;
pkey2->next = new Key_Attr;
pkey2 = pkey2->next;
count--;
}//end if
column = (Column_Info*)column->ColumnPtr.FileNext.MemAddr();
}//end while
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 + -