delete.c

来自「linux 下用c++ 开发的一个小型数据库系统」· C语言 代码 · 共 78 行

C
78
字号
#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 + =
减小字号Ctrl + -
显示快捷键?