-
Notifications
You must be signed in to change notification settings - Fork 1
/
db_rw.cpp
42 lines (38 loc) · 1.05 KB
/
db_rw.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
#include "db_rw.hh"
// for reading table creation commands and tuple insertion
// from previous sessions (stored in the file "db_data.dat")
// into the memory for current sessions
int read_db_dat () {
struct stat buf;
if (stat("db_data.dat", &buf) == -1) {
cout<<"> No prior DB found.\n";
return -1;
}
else
cout<<"> Prior DB found. Uploading data..."
<<"\n-------------------------------------";
fstream db_data;
db_data.open("db_data.dat");
string query_1, query_2;
query_1 = "O_o";
while (getline (db_data, query_2, ';')) {
if (query_1 != "O_o")
parser(query_1);
query_1 = query_2;
}
db_data.close();
cout<<"-------------------------------------\n"
<<"> Prior DB is now in memory.\n\n";
return 0;
}
// for writing table creation commands and tuple insertion
// from current sessions (appended to the file "db_data.dat")
// for future sessions
int write_db_dat (string query) {
fstream db_data;
db_data.open("db_data.dat", ios::app);
query += ";\n";
db_data<<query;
db_data.close();
return 0;
}