当前位置: 首页>>代码示例>>C++>>正文


C++ DB::openFile方法代码示例

本文整理汇总了C++中DB::openFile方法的典型用法代码示例。如果您正苦于以下问题:C++ DB::openFile方法的具体用法?C++ DB::openFile怎么用?C++ DB::openFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DB的用法示例。


在下文中一共展示了DB::openFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
  
  struct stat statusBuf;
  
  
  Error error;
  DB    db;
  File*	file1;
  File*	file2;
  File* file3;
  File* file4;
  int		i;
  const int   num = 100;
  int         j[num];
  
  // create buffer manager
  
  bufMgr = new BufMgr(num);
  
  // create dummy files
  
  lstat("test.1", &statusBuf);
  if (errno == ENOENT)
    errno = 0;
  else
    (void)db.destroyFile("test.1");
  
  lstat("test.2", &statusBuf);
  if (errno == ENOENT)
    errno = 0;
  else
    (void)db.destroyFile("test.2");
  
  lstat("test.3", &statusBuf);
  if (errno == ENOENT)
    errno = 0;
  else
    (void)db.destroyFile("test.3");
  
  lstat("test.4", &statusBuf);
  if (errno == ENOENT)
    errno = 0;
  else
    (void)db.destroyFile("test.4");
  
  CALL(db.createFile("test.1"));
  ASSERT(db.createFile("test.1") == FILEEXISTS);
  CALL(db.createFile("test.2"));
  CALL(db.createFile("test.3"));
  CALL(db.createFile("test.4"));
  
  CALL(db.openFile("test.1", file1));
  CALL(db.openFile("test.2", file2));
  CALL(db.openFile("test.3", file3));
  CALL(db.openFile("test.4", file4));
  
  // test buffer manager
  
  Page* page;
  Page* page2;
  Page* page3;
  char  cmp[PAGESIZE];
  int pageno, pageno2, pageno3;
  
  cout << "Allocating pages in a file..." << endl;
  for (i = 0; i < num; i++) {
    CALL(bufMgr->allocPage(file1, j[i], page));
    sprintf((char*)page, "test.1 Page %d %7.1f", j[i], (float)j[i]);
    CALL(bufMgr->unPinPage(file1, j[i], true));
  }
  cout <<"Test passed"<<endl<<endl;
  
  cout << "Reading pages back..." << endl;
  for (i = 0; i < num; i++) {
    CALL(bufMgr->readPage(file1, j[i], page));
    sprintf((char*)&cmp, "test.1 Page %d %7.1f", j[i], (float)j[i]);
    ASSERT(memcmp(page, &cmp, strlen((char*)&cmp)) == 0);
    CALL(bufMgr->unPinPage(file1, j[i], false));
  }
  cout<< "Test passed"<<endl<<endl;
  
  
  cout << "Writing and reading back multiple files..." << endl;
  cout << "Expected Result: ";
  cout << "The output will consist of the file name, page number, and a value."<<endl;
  cout << "The page number and the value should match."<<endl<<endl;
  
  for (i = 0; i < num/3; i++)
  {
    CALL(bufMgr->allocPage(file2, pageno2, page2));

    sprintf((char*)page2, "test.2 Page %d %7.1f", pageno2, (float)pageno2);
    
    CALL(bufMgr->allocPage(file3, pageno3, page3));
    sprintf((char*)page3, "test.3 Page %d %7.1f", pageno3, (float)pageno3);
    
    pageno = j[random() % num];
    CALL(bufMgr->readPage(file1, pageno, page));
    sprintf((char*)&cmp, "test.1 Page %d %7.1f", pageno, (float)pageno);
//.........这里部分代码省略.........
开发者ID:sekcheong,项目名称:buffer_management,代码行数:101,代码来源:testbuf.cpp


注:本文中的DB::openFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。