library works so far, can create tables
This commit is contained in:
parent
896a5cd55d
commit
09b179cccd
6
db.cpp
6
db.cpp
@ -24,9 +24,9 @@ void open_db(sqlite3* db) {
|
|||||||
void initialize_db(sqlite3* db) {
|
void initialize_db(sqlite3* db) {
|
||||||
// ugh, sqlite3_exec doesn't accept const strings, so i have to use const
|
// ugh, sqlite3_exec doesn't accept const strings, so i have to use const
|
||||||
// char*
|
// 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 primary key, name text, card_code varchar(20), verhicle int)";
|
||||||
const char* parkspot_table = "create table Park_spot (id int, taken boolean, customer_id 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, customer_id int, spot_id int, start real, end real, duration real)";
|
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;
|
int success;
|
||||||
|
|
||||||
success = sqlite3_exec(db, customer_table, callback, 0, &error_message);
|
success = sqlite3_exec(db, customer_table, callback, 0, &error_message);
|
||||||
|
18
main.cpp
18
main.cpp
@ -33,8 +33,22 @@ int main() {
|
|||||||
|
|
||||||
// test
|
// test
|
||||||
sqlite3* db;
|
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);
|
data::initialize_db(db);
|
||||||
sqlite3_close(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 */
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user