fix open_db

This commit is contained in:
MassiveAtoms 2019-06-24 22:09:43 -03:00
parent ecbf41ee07
commit 896a5cd55d
2 changed files with 6 additions and 42 deletions

12
db.cpp
View File

@ -14,8 +14,9 @@ static int callback(void* NotUsed, int argc, char** argv, char** azColName) {
}
void open_db(sqlite3* db) {
int status = sqlite3_open("database.sqlite", &db);
if (!status) {
int status = sqlite3_open("database.sqlite", &db); // for some reason, 0 is pass and 1 is erroring out
// so it prolly shouldn't be called status
if (status) {
std::cout << "Can't open database: " << sqlite3_errmsg(db) << "\n";
}
}
@ -23,12 +24,9 @@ void open_db(sqlite3* db) {
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* 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)";
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);

View File

@ -30,45 +30,11 @@ a wait function where 1 sec represents 1 hour irl.
using std::cout;
int main() {
std::vector<Park_spot> spots{1, 2, 3, 4, 5};
std::vector<Customer> customers{
{1, "Sagar Ram", Verhicle_type::small}, {2, "Shaq", Verhicle_type::medium}, {3, "Josh", Verhicle_type::large}, {4, "Stefano", Verhicle_type::small}};
// spots[1].clock(&customers[3]); // stefano parks at spot 2
// Wait(2);
// spots[3].clock(&customers[2]); // josh parks at spot 4
// Wait(1);
// spots[1].clock(&customers[3]); // stefano clocks out of spot 1
// Wait(5);
// spots[1].clock(&customers[1]); // shaq clocks in at spot 1
// Wait(6);
// spots[2].clock(&customers[0]); // sagar clocks in at spot 3. what the fuck
// // is he doing here?
// Wait(2);
// spots[2].clock(&customers[0]); // sagar clocks out from spot 2
// Wait(3);
// spots[3].clock(&customers[2]); // josh clocks out from spot 4
// spots[1].clock(&customers[1]); // shaq clocks out at spot 1
// spots[2].clock(&customers[1]); // shaq clocks out at spot 3
// Wait(4);
// spots[2].clock(&customers[1]); // shaq clocks out at spot 2
/*
so:
stefan parked for 3 secs
josh parked for 17 secs
shaq parked 2 times, once for 4 and another for 11 secs
sagar parked for 2 secs
*/
customers[0].gen_monthly();
customers[1].gen_monthly();
customers[2].gen_monthly();
customers[3].gen_monthly();
// test
sqlite3* db;
data::open_db(db);
cout << "PASS";
data::initialize_db(db);
sqlite3_close(db);
}