library works so far, can create tables

This commit is contained in:
MassiveAtoms 2019-06-26 06:40:43 -03:00
parent 896a5cd55d
commit 09b179cccd
2 changed files with 19 additions and 5 deletions

6
db.cpp
View File

@ -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);

View File

@ -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 */
}