initialize db

This commit is contained in:
MassiveAtoms
2019-06-24 21:09:33 -03:00
parent 20c5e25619
commit 9a10e33279
6 changed files with 110 additions and 7 deletions

View File

@@ -39,11 +39,13 @@ public:
void clock_out(int s_id);
// void gen_weekly(); TODO: this
void gen_monthly();
Customer(int id_, string name_);
Customer(int id_, string name_, Verhicle_type verhicle_);
private:
Verhicle_type verhicle;
vector<Park_time> park_instances;
string gen_cardcode();
};

View File

@@ -20,7 +20,6 @@ datetime end
Dit is gewoon een record van hoe lang, wie en waar iemand parkeert. Basically, een component van
de internal state van customer.
*/
class Park_time {
public:
int id;

56
headers/db.h Normal file
View File

@@ -0,0 +1,56 @@
#include <sqlite3.h>
#include <string>
#include <iostream>
namespace db
{
static int callback(void *NotUsed, int argc, char **argv, char **azColName);
sqlite3* db;
char* error_message;
void open_db(sqlite3* db_){
int success = sqlite3_open("sqlite.db", &db);
if (!success) {
std::cout << "Can't open database: "<<sqlite3_errmsg(db)<<"\n";
}
}
// stupid lib
void initialize_db(sqlite3* db_){
// ugh, sqlite3_exec doesn't accept const strings, so i have to use const char*
const char* customer_table = "create table Customer (id int, name varchar(50), card_code varchar(20), verhicle int)";
const char* parkspot_table = "create table Park_spot (id int, taken boolean, customer_id int)";
const char* parktime_table = "create table Park_time (id int, customer_id int, spot_id int, start real, end real, duration real)";
int success;
success = sqlite3_exec(db_, customer_table, callback, 0, &error_message);
if( success!=SQLITE_OK )
{
std::cout<<"SQL error: "<<sqlite3_errmsg(db)<<"\n";
sqlite3_free(error_message);
return; // TODO: error handling instead of just logging
}
success = sqlite3_exec(db_, parkspot_table, callback, 0, &error_message);
if( success!=SQLITE_OK )
{
std::cout<<"SQL error: "<<sqlite3_errmsg(db)<<"\n";
sqlite3_free(error_message);
return; // TODO: error handling instead of just logging
}
success = sqlite3_exec(db_, parktime_table, callback, 0, &error_message);
if( success!=SQLITE_OK )
{
std::cout<<"SQL error: "<<sqlite3_errmsg(db)<<"\n";
sqlite3_free(error_message);
return; // TODO: error handling instead of just logging
}
}
}