35 lines
1.4 KiB
C++
35 lines
1.4 KiB
C++
#include "headers/data.h"
|
|
|
|
namespace data {
|
|
|
|
SQLite::Database start_db() {
|
|
/*
|
|
Opens the database, creates it if it can't find the file.
|
|
Then creates tables if they don't exist
|
|
*/
|
|
SQLite::Database db("test.db3", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
|
|
while (sodium_init() < 0) {
|
|
std::cout << "SODIUM NOT WORKING";
|
|
/*
|
|
This shouldn't be here, really, but I can't think of a better place
|
|
where it runs at least once. This seeds the random generator needed for
|
|
salts and other stuff, and needs to be run at least once when working
|
|
with any libsodium function. And since this definitely needs to be run at least once, why
|
|
not include it here? you can't (well, shouldn't be able to) login into anything if this
|
|
doesn't run, since you need to compare passwords to login, and then running the program is
|
|
as futile as not opening the db correctly.
|
|
*/
|
|
}
|
|
db.exec(
|
|
"create table if not exists Customer (id integer primary key, name "
|
|
"text, password text, vehicle int, telephone text, role int)");
|
|
db.exec(
|
|
"create table if not exists Park_spot (id integer primary key, taken "
|
|
"int, customer_id int, vehicle_type int)");
|
|
db.exec(
|
|
"create table if not exists Park_time (id integer primary key, "
|
|
"customer_id int, spot_id int, start int, end int, duration int)");
|
|
|
|
return db;
|
|
}
|
|
} // namespace data
|