code compiles, doesnt run tho

This commit is contained in:
MassiveAtoms
2019-06-24 21:42:08 -03:00
parent 9a10e33279
commit ecbf41ee07
6 changed files with 117 additions and 118 deletions

View File

@@ -2,14 +2,14 @@
#define CUSTOMER_H
#pragma once
#include <vector>
#include <string>
#include "Park_time.h"
#include <string>
#include <vector>
using std::vector;
using std::string;
using std::vector;
// enum type is basically een manier om categories te representen als een integer in the background, maar om t in code
// enum type is basically een manier om categories te representen als een integer in the background, maar om t in code
// aan te geven als de actual category.
enum class Verhicle_type {
small = 1,
@@ -22,16 +22,16 @@ db repr of Customer
int id (not null, auto increment)
string name (not nulll)
string card_code (not null)
Dit moet nog verandert worden.
Dit moet nog verandert worden.
card code zou eigenlijk een randomly generated string moeten zijn, die je bv. op een ndf card zou opslaan en zo zou
card code zou eigenlijk een randomly generated string moeten zijn, die je bv. op een ndf card zou opslaan en zo zou
authenticaten bij je parking spot. We kunnen dit ipv of samen met een password gebruiken.
clock in en out creeert en compleet een park_time object. Voegt het toe aan een vector.
*/
class Customer {
public:
public:
int id;
string name;
string card_code;
@@ -41,13 +41,10 @@ public:
void gen_monthly();
Customer(int id_, string name_, Verhicle_type verhicle_);
private:
private:
Verhicle_type verhicle;
vector<Park_time> park_instances;
string gen_cardcode();
};
#endif // CUSTOMER_H

View File

@@ -1,56 +1,16 @@
#include <iostream>
#include <sqlite3.h>
#include <string>
#include <iostream>
namespace db
{
namespace data {
static int callback(void *NotUsed, int argc, char **argv, char **azColName);
static int callback(void* NotUsed, int argc, char** argv, char** azColName);
sqlite3* db;
char* error_message;
void open_db(sqlite3* db_);
/*
this initializes the table in the database.
*/
void initialize_db(sqlite3* db_);
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
}
}
}
} // namespace data