📄 delete.c
字号:
#include "catalog.h"#include "query.h"/* * Deletes records from a specified relation. * * Returns: * OK on success * an error code otherwise */const Status QU_Delete(const string & relation, const string & attrName, const Operator op, const Datatype type, const char *attrValue){// part 5 HeapFileScan *hfs ; Status status ; RID recrid ; int recNum = 0 ; AttrDesc record ; int intval ; float flval ; hfs = new HeapFileScan( relation, status) ; if (status != OK) return status ; if (attrName.empty()){ hfs->startScan( 0, 0, STRING, NULL, EQ) ; while(hfs->scanNext(recrid) != FILEEOF){ hfs->deleteRecord() ; recNum++ ; } printf("\n Table (%s) %d record (s) deleteed!\n", relation.c_str(), recNum) ; delete hfs ; return OK ; } status = attrCat->getInfo( relation, attrName, record) ; if (status != OK){ delete hfs ; return status ; } if (record.attrType == INTEGER){ intval = atoi(attrValue) ; hfs->startScan( record.attrOffset, record.attrLen, (Datatype)record.attrType, (char *)&intval, op) ; } if (record.attrType == FLOAT){ flval =(float)atof(attrValue) ; hfs->startScan( record.attrOffset, record.attrLen, (Datatype)record.attrType, (char *)&flval, op) ; } if (record.attrType == STRING){ hfs->startScan( record.attrOffset, record.attrLen, (Datatype)record.attrType, attrValue, op) ; } while (hfs->scanNext(recrid) != FILEEOF){ hfs->deleteRecord() ; recNum++ ; } printf("\n Table (%s) %d record (s) deleteed!\n", relation.c_str(), recNum) ; delete hfs ; return OK;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -