#include "headers/db.h" namespace data { char* error_message; // no clue, prolly error message static int callback(void* NotUsed, int argc, char** argv, char** azColName) { int i; for (i = 0; i < argc; i++) { std::cout << azColName[i] << " = " << (argv[i] ? argv[i] : "NULL") << "\n"; } std::cout << "\n"; return 0; } void open_db(sqlite3* db) { 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"; } } 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 primary key, name text, card_code varchar(20), verhicle int)"; const char* parkspot_table = "create table Park_spot (id int primary key, taken boolean, customer_id int)"; const char* parktime_table = "create table Park_time (id int primary key, customer_id int, spot_id int, start real, end real, duration real)"; int success; success = sqlite3_exec(db, customer_table, callback, 0, &error_message); if (success != SQLITE_OK) { std::cout << "SQL error: " << sqlite3_errmsg(db) << "\n"; sqlite3_free(error_message); return; // TODO: error handling instead of just logging } success = sqlite3_exec(db, parkspot_table, callback, 0, &error_message); if (success != SQLITE_OK) { std::cout << "SQL error: " << sqlite3_errmsg(db) << "\n"; sqlite3_free(error_message); return; // TODO: error handling instead of just logging } success = sqlite3_exec(db, parktime_table, callback, 0, &error_message); if (success != SQLITE_OK) { std::cout << "SQL error: " << sqlite3_errmsg(db) << "\n"; sqlite3_free(error_message); return; // TODO: error handling instead of just logging } } } // namespace data