Пример #1
0
RC SM_Manager::DropTable(const char *relName){
  string rel_name(relName);
  
  //drop in system catalog
  RM_FileScan system_scanner(system_fh, STRING, RELNAME_LENGTH, 0, EQ_OP, 
                             (void*)relName, strlen(relName));
  RC ret;
  RM_Record record;
  ret=system_scanner.GetNextRec(record);
  if (ret==NOT_FOUND){
    return NOT_FOUND;
  }
  RID rid;
  record.GetRid(rid);
  system_fh.DeleteRec(rid);
  //------------------------

  //drop in attribute catalog
  RM_FileScan attribute_scanner(attribute_fh, STRING, RELNAME_LENGTH, 0, EQ_OP, 
                                (void*)relName, strlen(relName));
  while( (ret=attribute_scanner.GetNextRec(record)) != NOT_FOUND ){
    record.GetRid(rid);
    attribute_fh.DeleteRec(rid);
  }
  //-----------------------
  
  return OK;
}
Пример #2
0
RC SM_Manager::DropTable(const char *relName){
  string rel_name(relName);
  
  //drop in system catalog
  RM_FileScan system_scanner(system_fh, STRING, RELNAME_LENGTH, 0, EQ_OP, 
                             (void*)relName, strlen(relName));
  RC ret;
  RM_Record record;
  ret=system_scanner.GetNextRec(record);
  if (ret==NOT_FOUND){
    return NOT_FOUND;
  }
  RID rid;
  record.GetRid(rid);
  system_fh.DeleteRec(rid);
  //------------------------

  //drop in attribute catalog
  RM_FileScan attribute_scanner(attribute_fh, STRING, RELNAME_LENGTH, 0, EQ_OP, 
                                (void*)relName, strlen(relName));
  while( (ret=attribute_scanner.GetNextRec(record)) != NOT_FOUND ){
    record.GetRid(rid);
    attribute_fh.DeleteRec(rid);
  }
  system((string("mv -f ")+db_dir+string(relName)+" "+db_dir+"dust/"+string(relName)).c_str());
  
  RM_FileScan check_scanner(check_fh, STRING, RELNAME_LENGTH, 0, EQ_OP, 
                                (void*)relName, strlen(relName));
  while( (ret=attribute_scanner.GetNextRec(record)) != NOT_FOUND ){
    Byte *mem;
    record.GetRid(rid);
    record.GetData(mem);
    attribute_fh.DeleteRec(rid);
    string CheckData=string("__checkdata__")+rel_name+(char*)(mem+RELNAME_LENGTH);
    system((string("mv -f ")+db_dir+CheckData+" "+db_dir+"dust/"+CheckData).c_str());
  }

  attribute_fh.ForcePages();
  system_fh.ForcePages();
  check_fh.ForcePages();
  
  //-----------------------
  
  return OK;
}
Пример #3
0
void SM_Manager::DropIndex(const char *relName, const char* AttrName)
{
  RM_FileScan attribute_scanner(attribute_fh, STRING, RELNAME_LENGTH, 0, EQ_OP, 
                                (void*)relName, strlen(relName));
  RC ret;
  RM_Record record;
  Byte *mem;
  RID rid;
  int mark=0;
  while( (ret=attribute_scanner.GetNextRec(record)) != NOT_FOUND ){
    record.GetRid(rid);
  //  attribute_fh.DeleteRec(rid);
    record.GetData(mem);
    if (GenString((char *)(mem+RELNAME_LENGTH),ATTRNAME_LENGTH)==GenString((char *)AttrName,strlen(AttrName))){
      mark=*(int*)(mem+RELNAME_LENGTH+ATTRNAME_LENGTH+12);
      if(mark&1) mark=mark-1;
      memcpy((mem+RELNAME_LENGTH+ATTRNAME_LENGTH+12), &mark , 4);
      RM_Record rec=RM_Record(mem, attribute_fh.GetRecordSize(), rid);
      attribute_fh.UpdateRec(rec);
    }
  }
  attribute_fh.ForcePages();
}
Пример #4
0
static RC PrintTable(SM_DbHandle &db, const char *tableName)
{
    RC rc;

    RM_FileHandle *pTable;
    if ((rc = db.FindTableHandle(tableName, pTable)))
        return rc;
    int recordSize = pTable->header.recordSize;

    vector<SM_ActiveAttr> *attributes;
    if ((rc = db.AllAttributes(tableName, attributes)))
        return rc;

    RM_FileScan allScan;
    if ((rc = allScan.OpenScan(*pTable, INT, 0, 0, 0, NO_OP, NULL)))
        return rc;
    RM_Record record;
    int recordCount = 0;

    printf("Table: %s\n", tableName);
    while ((rc = allScan.GetNextRec(record)) == 0) {
        RID rid;
        if ((rc = record.GetRid(rid)))
            return rc;
        PageNum pageNum;
        int slotNum;
        if ((rc = rid.GetPageNum(pageNum)))
            return rc;
        if ((rc = rid.GetSlotNum(slotNum)))
            return rc;

        char *data;
        if ((rc = record.GetData(data)))
            return rc;

        printf("RID: (%d,%d)\n", pageNum, slotNum);
        vector<SM_ActiveAttr>::iterator pAttr;

        int *pNullBitmap = (int *)(data + recordSize - sizeof(int));
        for (pAttr = attributes->begin(); pAttr != attributes->end(); ++pAttr) {
            SM_Attribute *attr = &pAttr->record;
            if (*pNullBitmap & (1 << attr->number))
                printf("  %s: Null\n", attr->attrName);
            else if (attr->attrType == INT)
                printf("  %s: %d\n", attr->attrName, *(int *)(data + attr->attrOffset));
            else if (attr->attrType == FLOAT)
                printf("  %s: %f\n", attr->attrName, *(float *)(data + attr->attrOffset));
            else if (attr->attrType == STRING)
                printf("  %s: %s\n", attr->attrName, data + attr->attrOffset);
        }
        printf("\n");
        recordCount++;
    }
    if (rc != RM_ERR_EOF)
        return rc;
    if ((rc = allScan.CloseScan()))
        return rc;
        printf("\nTotal %d records.\n", recordCount);

    return 0;
}