-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.cpp
More file actions
100 lines (85 loc) · 1.64 KB
/
Copy pathDatabase.cpp
File metadata and controls
100 lines (85 loc) · 1.64 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef DATABASE_CPP
#define DATABASE_CPP
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "Database.h"
#include "UsefulFunctions.h"
using namespace std;
Database::Database()
{
int i = 1;
dbname = "New Database";
string fname = dbname + ".txt";
fstream newfile(dbname);
bool exists = true;
while (exists)
{
if (fileExists(fname))
{
newfile.close();
dbname = "New Database" + i;
fname = dbname + ".txt";
fstream newfile(fname);
i++;
}
else
{
exists = false;
}
}
newfile.close();
ntables = 0;
tnames = nullptr;
if (fileExists("Databases.txt"))
{
fstream dbfile;
dbfile.open("Databases.txt", ios::in);
dbfile << dbname << "\t" << ntables << endl;
dbfile.close;
}
else
{
fstream dbfile("Databases.txt");
dbfile << dbname << "\t" << ntables << endl;
dbfile.close();
}
}
Database::Database(const Database& other)
{
unsigned int j = 1;
bool exists = true;
dbname = other.dbname + " copy";
ntables = other.ntables;
tnames = new string[ntables];
string filename = dbname + ".txt";
fstream newfile(filename);
for (unsigned int i = 0; i < ntables; i++)
{
tnames[i] = other.tnames[i];
}
while (exists)
{
if (fileExists(filename))
{
newfile.close();
dbname += j;
filename = dbname + ".txt";
fstream newfile(filename);
j++;
}
else
{
exists = false;
}
}
}
void Database::addTable(string tableName)
{
fstream dbfile;
string filename = this->dbname + ".txt";
dbfile.open(filename, ios::app);
dbfile << tableName;
}
#endif /* DATABASE_CPP */