diff --git a/db.cpp b/db.cpp index 182fe97..3627734 100644 --- a/db.cpp +++ b/db.cpp @@ -24,9 +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* 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* 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); diff --git a/main.cpp b/main.cpp index 85751d9..1ccf7ac 100644 --- a/main.cpp +++ b/main.cpp @@ -33,8 +33,22 @@ int main() { // test sqlite3* db; - data::open_db(db); - cout << "PASS"; + + // opening the db. somehow, this does not work when placing inside a function. HALP + + int status = sqlite3_open("database.sqlite", &db); // TODO: Name this better. works like main() in unix. + if (status) { + std::cout << "Can't open database: " << sqlite3_errmsg(db) << "\n"; + } + + // TODO: edit function to check if any of the table exists before creating them + // or a simple file that gets saved on first run, and the function checks if that + // file exists to determine if it should create tables or not. data::initialize_db(db); sqlite3_close(db); + + /* + Creates tables, library seems to work so far. + Gonnay try using another library. This one works,but seems a bit of a pain + especially since it seems to be using c-style 'not modern' cpp */ }