-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.cpp
75 lines (66 loc) · 1.84 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "storage.h"
#include "Test.h"
int main(int argc, char *argv[])
{
//printf("hello");
Storage StorageManager;
DbMetaHead dbhead;
char fileName[15] = "tinydb.mat";
StorageManager.initDB(&dbhead, fileName);
StorageManager.showDbInfo(&dbhead);
StorageManager.fileOpt.deleteFile(&dbhead, 0);
StorageManager.pageOpt.recyAllPage(&dbhead);
StorageManager.showDbInfo(&dbhead);
int fileID = StorageManager.fileOpt.createFile(&dbhead, NORMAL_FILE, 1);
printf("创建文件%d成功!\n", fileID);
//int mapfileID = StorageManager.fileOpt.createFile(&dbhead, MAP_FILE, 1);
memToDisk(&dbhead);
StorageManager.showDbInfo(&dbhead);
//int fileID = 0;
int num = 2000;
for (int i = 0; i < num; i++) {
struct Student stu = { i, "abc", 30 + i, 5000 + i };
char str[1000];
sprintf(str, "%ld", stu.rid);
strcat(str, stu.name);
char tmp[100];
sprintf(tmp, "%d", stu.age);
sprintf(tmp, "%d", stu.weight);
strcat(str, tmp);
if (i % 10 == 0)
printf("str: %s\n", str);
StorageManager.fileOpt.writeFile(&dbhead, fileID, strlen(str), str);
}
char des[1000];
StorageManager.fileOpt.readFile(&dbhead, fileID, des);
memToDisk(&dbhead);
StorageManager.showDbInfo(&dbhead);
fclose(dbhead.dataPath);
free(dbhead.FreeSpace_bitMap);
// 更改文件名
time_t tt = time(NULL);//这句返回的只是一个时间cuo
tm* t = localtime(&tt);
printf("%d-%02d-%02d %02d:%02d:%02d\n",
t->tm_year + 1900,
t->tm_mon + 1,
t->tm_mday,
t->tm_hour,
t->tm_min,
t->tm_sec);
char time[50];
sprintf(time, "%d", t->tm_year + 1900);
char tmp[10];
sprintf(tmp, "-%d", t->tm_mon + 1);
strcat(time, tmp);
sprintf(tmp, "-%d", t->tm_mday);
strcat(time, tmp);
sprintf(tmp, " %d", t->tm_min);
strcat(time, tmp);
sprintf(tmp, "_%d", t->tm_sec);
strcat(time, tmp);
sprintf(tmp, "_%d", t->tm_sec);
strcat(time, tmp);
strcat(time, ".mat");
rename(fileName, time);
return 0;
}