From d3ac836657afe8561974fb011e4cecc656414b1a Mon Sep 17 00:00:00 2001 From: MassiveAtoms Date: Sat, 6 Jul 2019 12:14:18 -0300 Subject: [PATCH] ammend parkspot to include vehicletype --- Park_spot.cpp | 10 ++++++---- data.cpp | 2 +- headers/Park_spot.h | 5 +++-- main.cpp | 11 ++++------- test.db3 | Bin 16384 -> 16384 bytes 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Park_spot.cpp b/Park_spot.cpp index e64e8e1..7efc6cf 100644 --- a/Park_spot.cpp +++ b/Park_spot.cpp @@ -2,14 +2,15 @@ // constructors -Park_spot::Park_spot() - : parked_customer{0}, id{auto_increment_db() + 1}, taken{false} { +Park_spot::Park_spot(Vehicle_type v_type_) + : parked_customer{0}, id{auto_increment_db() + 1}, taken{false}, v_type{v_type_} { save_db(); } -Park_spot::Park_spot(int id_, bool taken_, int parked) +Park_spot::Park_spot(int id_, bool taken_, int parked,Vehicle_type v_type_) : parked_customer{parked}, id{id_}, + v_type{v_type_}, taken{taken_} // TODO: think about how init parked? {} @@ -48,8 +49,9 @@ void Park_spot::update_db() { void Park_spot::save_db() { //(int id, bool taken, int customer_id) - string statement{"insert into Park_spot values ( , , );"}; + string statement{"insert into Park_spot values ( , , , );"}; // after ( = 28) + statement.insert(36, to_string(int(v_type))); statement.insert(34, "NULL"); statement.insert(32, "0"); statement.insert(30, to_string(id)); diff --git a/data.cpp b/data.cpp index be27c0d..5c000b9 100644 --- a/data.cpp +++ b/data.cpp @@ -24,7 +24,7 @@ SQLite::Database start_db() { // getting errors when using bool, so i used an int instead. db.exec( "create table if not exists Park_spot (id integer primary key, taken " - "int, customer_id int)"); + "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)"); diff --git a/headers/Park_spot.h b/headers/Park_spot.h index e50dfdc..068fc55 100644 --- a/headers/Park_spot.h +++ b/headers/Park_spot.h @@ -18,9 +18,10 @@ class Park_spot { int id; bool taken; int parked_customer; + Vehicle_type v_type; - Park_spot(); - Park_spot(int id_, bool taken_, int parked); + Park_spot(Vehicle_type v_type_); + Park_spot(int id_, bool taken_, int parked, Vehicle_type v_type_); void clock(Customer& c_customer); private: diff --git a/main.cpp b/main.cpp index 7d88f59..dd7794f 100644 --- a/main.cpp +++ b/main.cpp @@ -70,12 +70,10 @@ For now, it's just here in case you want an easy way to store customers. */ int main() { + // state of db: + // er zijn 10 parkspots, 5 met biketype en 5 met pickup type // er is een customer met id 1(testcustomer) met password "password" - // Customer test { - // "testcustomer", "password", Vehicle_type::bike - // }; - interface(); @@ -89,13 +87,12 @@ concurrency issue. Do not move this. vector populate_spots() { vector spots; SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 0;"); - // query.bind(1, 2); while (query.executeStep()) { int id = query.getColumn(0); int taken = query.getColumn(1); int cid = query.getColumn(2); - // park_customers.push_back(query_customer_with_id(cid)); - spots.push_back({id, taken, cid}); + Vehicle_type vtype = Vehicle_type(int(query.getColumn(3))); + spots.push_back({id, taken, cid, vtype}); } return spots; } \ No newline at end of file diff --git a/test.db3 b/test.db3 index 6e83b13452cc5fa52980122413fb0f25f2951302..fc57d5fe69782b8fce6ed43c9e47b7490999f602 100644 GIT binary patch delta 272 zcmZo@U~Fh$oFL7}H&Mn}n2$lvM1hxqfq|K?mVv*ApO3G0V*LG6v|RFGLv&s<4Y$rOHN9LCS$Swq zqGP0GT6$_E$T3{}TN(I&@_*!i#s7%^HveV*GyF&R_wsMuET}M(-aM8#bsp~8!abKxR$gF0NoqlazH3f?VL@p?Vwjs@ zpo(LKd!=KTVOU~*lv6;2rK?*?rglYywt-QUOHM{shO47bxp%&!Z<=Xl;35M7AOZj~ CyD9qs