From 5ff6670b3c201e0fa95cedd417d6dfdb833d0824 Mon Sep 17 00:00:00 2001 From: MassiveAtoms Date: Mon, 1 Jul 2019 22:11:46 -0300 Subject: [PATCH] working, but confused --- Query.cpp | 41 ++++++++++++++++++++++++++++------------- headers/Query.h | 7 +++---- main.cpp | 37 +++++++++++++++++++++++++++++-------- 3 files changed, 60 insertions(+), 25 deletions(-) diff --git a/Query.cpp b/Query.cpp index 4cd3840..bbc1a26 100644 --- a/Query.cpp +++ b/Query.cpp @@ -78,17 +78,32 @@ Customer query_customer_with_id(int id) { // -------------- paroking spots -vector query_all_parking_spots() { - vector spots; - SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 2;"); - // 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}); - } - return spots; -} +// vector query_all_parking_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}); +// } +// return spots; +// } + + +// 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}); +// } +// return spots; +// } \ No newline at end of file diff --git a/headers/Query.h b/headers/Query.h index e92f467..9821878 100644 --- a/headers/Query.h +++ b/headers/Query.h @@ -11,11 +11,10 @@ vector query_parktimes_for_customer(int cid); vector query_customer_with_name(string name); Customer query_customer_with_id(int id); -vector query_all_parking_spots(); // used for initializing the parking spots at start of the program +// vector query_all_parking_spots(); // used for initializing the parking spots at start of the program +vector populate_spots(); + -static vector parking_spots = query_all_parking_spots(); // to save the parking spots in memory -static vector park_customers; -// save the customers that are parked in here #endif // CUSTOMER_H \ No newline at end of file diff --git a/main.cpp b/main.cpp index ec76f67..3fc3dd5 100644 --- a/main.cpp +++ b/main.cpp @@ -29,14 +29,35 @@ a wait function where 1 sec represents 1 hour irl. std::this_thread::sleep_for(seconds{sec}); } -int main() { - // Customer sagar = query_customer_with_name("stefan udit")[0]; - Customer sagar = query_customer_with_id(2); - cout << sagar.id << "," << sagar.name << "," << sagar.password; - // cout << parking_spots.size(); +static vector parking_spots = populate_spots(); // to save the parking spots in memory +static vector park_customers; // save the customers that are parked in here - // for (auto i : parking_spots){ - // cout << i.id << "," << i.parked_customer; - // } +int main() { + Customer sagar = query_customer_with_name("stefan udit")[0]; + Customer sagar1 = query_customer_with_id(2); + cout << sagar.id << "," << sagar.name << "," << sagar.password<< "\n"; + cout << sagar1.id << "," << sagar1.name << "," << sagar1.password; + cout << parking_spots.size(); + + for (auto i : parking_spots){ + cout << "\n" << i.id << "," << i.parked_customer; + } } + + + + +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}); + } + return spots; +} \ No newline at end of file