int main() { PF_Manager pfm; RM_Manager rmm(pfm); IX_Manager ixm(pfm); SM_Manager smm(ixm, rmm); smm.OpenDb(DBNAME); AttrInfo attrs[3]; attrs[0].attrType = STRING; attrs[0].attrLength = 30; attrs[0].attrName = "departmentName"; attrs[1].attrType = INT; attrs[1].attrLength = 4; attrs[1].attrName = "buildYear"; attrs[2].attrType = FLOAT; attrs[2].attrLength = 4; attrs[2].attrName = "budget"; RC rc; // if(rc = smm.DropTable("departments")) { // SM_PrintError(rc); // exit(1); // } if(rc = smm.CreateTable("departments", 3, attrs)) { SM_PrintError(rc); } if(rc = smm.CreateTable("departments", 3, attrs)) { SM_PrintError(rc); } // if(rc = smm.CreateIndex("departments", "departmentName")) printf("rc=%d\n", rc); // if(rc = smm.CreateIndex("departments", "buildYear")) printf("rc=%d\n", rc); // if(rc = smm.CreateIndex("departments", "budget")) printf("rc=%d\n", rc); if(rc = smm.DropIndex("departments", "departmentName")) { SM_PrintError(rc); } // smm.DropTable("departments"); // smm.Load("departments", "/Users/dddong/workspace/ClionProjects/miniSqlFrom0/dep.data"); smm.Print("departments"); smm.Print("relcat"); smm.Print("attrcat"); if(rc = smm.CloseDb()) { SM_PrintError(rc); exit(1); } }
RC SM_Manager::CloseDb(){ RC ret=rmm.CloseFile(system_fh); if (ret!=OK){ SM_PrintError(ret); return SYSTEM_CATALOG_CLOSE_ERROR; } ret=rmm.CloseFile(attribute_fh); if (ret!=OK){ SM_PrintError(ret); return ATTRIBUTE_CATALOG_CLOSE_ERROR; } ret=rmm.CloseFile(check_fh); return OK; }
RC SM_Manager::OpenDb(const char *db_name){ //cout <<"iin"<<endl; db_dir=string(db_name)+SYS_SEP; RC ret=rmm.OpenFile((db_dir+SYSTEM_CATALOG_NAME).c_str(), system_fh); if (ret!=OK){ SM_PrintError(ret); return SYSTEM_CATALOG_OPEN_ERROR; } ret=rmm.OpenFile((db_dir+ATTRIBUTE_CATALOG_NAME).c_str(), attribute_fh); if (ret!=OK){ SM_PrintError(ret); return ATTRIBUTE_CATALOG_OPEN_ERROR; } ret=rmm.OpenFile((db_dir+CHECK_CATALOG_NAME).c_str(), check_fh); return OK; }