ammend parkspot to include vehicletype

This commit is contained in:
MassiveAtoms 2019-07-06 12:14:18 -03:00
parent 70fcbc274b
commit d3ac836657
5 changed files with 14 additions and 14 deletions

View File

@ -2,14 +2,15 @@
// constructors // constructors
Park_spot::Park_spot() Park_spot::Park_spot(Vehicle_type v_type_)
: parked_customer{0}, id{auto_increment_db() + 1}, taken{false} { : parked_customer{0}, id{auto_increment_db() + 1}, taken{false}, v_type{v_type_} {
save_db(); 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}, : parked_customer{parked},
id{id_}, id{id_},
v_type{v_type_},
taken{taken_} // TODO: think about how init parked? taken{taken_} // TODO: think about how init parked?
{} {}
@ -48,8 +49,9 @@ void Park_spot::update_db() {
void Park_spot::save_db() { void Park_spot::save_db() {
//(int id, bool taken, int customer_id) //(int id, bool taken, int customer_id)
string statement{"insert into Park_spot values ( , , );"}; string statement{"insert into Park_spot values ( , , , );"};
// after ( = 28) // after ( = 28)
statement.insert(36, to_string(int(v_type)));
statement.insert(34, "NULL"); statement.insert(34, "NULL");
statement.insert(32, "0"); statement.insert(32, "0");
statement.insert(30, to_string(id)); statement.insert(30, to_string(id));

View File

@ -24,7 +24,7 @@ SQLite::Database start_db() {
// getting errors when using bool, so i used an int instead. // getting errors when using bool, so i used an int instead.
db.exec( db.exec(
"create table if not exists Park_spot (id integer primary key, taken " "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( db.exec(
"create table if not exists Park_time (id integer primary key, " "create table if not exists Park_time (id integer primary key, "
"customer_id int, spot_id int, start int, end int, duration int)"); "customer_id int, spot_id int, start int, end int, duration int)");

View File

@ -18,9 +18,10 @@ class Park_spot {
int id; int id;
bool taken; bool taken;
int parked_customer; int parked_customer;
Vehicle_type v_type;
Park_spot(); Park_spot(Vehicle_type v_type_);
Park_spot(int id_, bool taken_, int parked); Park_spot(int id_, bool taken_, int parked, Vehicle_type v_type_);
void clock(Customer& c_customer); void clock(Customer& c_customer);
private: private:

View File

@ -70,12 +70,10 @@ For now, it's just here in case you want an easy way to store customers.
*/ */
int main() { 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" // er is een customer met id 1(testcustomer) met password "password"
// Customer test {
// "testcustomer", "password", Vehicle_type::bike
// };
interface(); interface();
@ -89,13 +87,12 @@ concurrency issue. Do not move this.
vector<Park_spot> populate_spots() { vector<Park_spot> populate_spots() {
vector<Park_spot> spots; vector<Park_spot> spots;
SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 0;"); SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 0;");
// query.bind(1, 2);
while (query.executeStep()) { while (query.executeStep()) {
int id = query.getColumn(0); int id = query.getColumn(0);
int taken = query.getColumn(1); int taken = query.getColumn(1);
int cid = query.getColumn(2); int cid = query.getColumn(2);
// park_customers.push_back(query_customer_with_id(cid)); Vehicle_type vtype = Vehicle_type(int(query.getColumn(3)));
spots.push_back({id, taken, cid}); spots.push_back({id, taken, cid, vtype});
} }
return spots; return spots;
} }

BIN
test.db3

Binary file not shown.