50 lines
1.8 KiB
C++
50 lines
1.8 KiB
C++
#include "headers/Query.h"
|
|
|
|
vector<Park_time> query_Parktime_for_customer(int cid) {
|
|
/*
|
|
This is needed to initialize the park_instances for the customer constructor
|
|
that is supposed to create a customer from data in the db.
|
|
This should not be called on on it's own outside query_customer();
|
|
*/
|
|
vector<Park_time> park_times;
|
|
|
|
SQLite::Statement query(data::db,
|
|
"SELECT * FROM Park_time WHERE customer_id = ?;");
|
|
query.bind(1, cid);
|
|
while (query.executeStep()) {
|
|
int id = query.getColumn(0);
|
|
int spot_id = query.getColumn(2);
|
|
int start = query.getColumn(3);
|
|
int duration = query.getColumn(5);
|
|
|
|
Park_time result{id, cid, spot_id, start, duration};
|
|
park_times.push_back(result);
|
|
}
|
|
query.reset();
|
|
return park_times;
|
|
}
|
|
|
|
vector<Customer> query_customer_with_name(string name) {
|
|
/*
|
|
We use this instead of plain customers because:
|
|
1. no error handling needed here if there are no customers
|
|
2. multiple customers could be returned with the same name.
|
|
*/
|
|
vector<Customer> result;
|
|
SQLite::Statement query(data::db,
|
|
"SELECT * FROM Customer WHERE name = '?';");
|
|
query.bind(1, name);
|
|
while (query.executeStep()) {
|
|
// (id integer primary key, name text, card_code varchar(20), verhicle
|
|
// int) (int id_, string name_, string card_code_, Verhicle_type
|
|
// verhicle_, vector<Park_time> instances)
|
|
|
|
int id = query.getColumn(0);
|
|
string name = query.getColumn(1);
|
|
string password = query.getColumn(2);
|
|
// int verhicle = query.getColumn(3); // cast to verhicle
|
|
vector<Park_time> park_instances = query_Parktime_for_customer(id);
|
|
// result.push_back(Customer{id, name, password, Verhicle_type(verhicle), park_instances});
|
|
}
|
|
return result;
|
|
} |