本文整理汇总了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);
//.........这里部分代码省略.........