2019-06-26 18:12:23 +00:00
|
|
|
#include "headers/data.h"
|
|
|
|
|
|
|
|
namespace data {
|
|
|
|
|
2019-07-01 17:23:15 +00:00
|
|
|
SQLite::Database start_db() {
|
2019-07-02 18:40:37 +00:00
|
|
|
/*
|
|
|
|
Opens the database, creates it if it can't find the file.
|
|
|
|
*/
|
2019-06-30 03:37:18 +00:00
|
|
|
SQLite::Database db("test.db3",
|
|
|
|
SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
|
2019-07-01 17:23:15 +00:00
|
|
|
while (sodium_init() < 0) {
|
2019-06-30 17:49:20 +00:00
|
|
|
std::cout << "SODIUM NOT WORKING";
|
2019-07-02 18:40:37 +00:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
2019-06-30 17:49:20 +00:00
|
|
|
}
|
2019-07-02 18:40:37 +00:00
|
|
|
//sql syntax is surprisingly readable.
|
2019-06-30 03:37:18 +00:00
|
|
|
db.exec(
|
|
|
|
"create table if not exists Customer (id integer primary key, name "
|
2019-07-06 14:52:01 +00:00
|
|
|
"text, password text, vehicle int)");
|
2019-07-02 18:40:37 +00:00
|
|
|
// getting errors when using bool, so i used an int instead.
|
2019-06-30 03:37:18 +00:00
|
|
|
db.exec(
|
|
|
|
"create table if not exists Park_spot (id integer primary key, taken "
|
2019-07-06 15:14:18 +00:00
|
|
|
"int, customer_id int, vehicle_type int)");
|
2019-06-30 03:37:18 +00:00
|
|
|
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)");
|
2019-06-26 18:12:23 +00:00
|
|
|
|
|
|
|
return db;
|
|
|
|
}
|
|
|
|
} // namespace data
|