parent
b6e51b6f06
commit
d53c0762be
13
Makefile
13
Makefile
|
@ -13,10 +13,18 @@ CONFIG=src/config.h #config file
|
||||||
|
|
||||||
|
|
||||||
#targets
|
#targets
|
||||||
debug: test ui planner db iCal config llist
|
debug: db test ui planner iCal config llist
|
||||||
gcc test.o ui.o planner.o db.o iCal.o llist.o -o debugOut
|
gcc test.o ui.o planner.o db.o iCal.o llist.o -o debugOut
|
||||||
|
|
||||||
config: $(CONFIG)
|
config: $(CONFIG)
|
||||||
|
db: $(DBF)
|
||||||
|
curl -L https://sqlite.org/2024/sqlite-amalgamation-3470200.zip --output src/sqlite.zip
|
||||||
|
unzip src/sqlite.zip
|
||||||
|
mv sqlite-amalgamation-3470200/* src/
|
||||||
|
rm -rf sqlite-amalgamation-3470200
|
||||||
|
gcc -c $(CFLAGS) $(DBF)
|
||||||
|
|
||||||
|
|
||||||
llist: $(LLST)
|
llist: $(LLST)
|
||||||
gcc -c $(CFLAGS) $(LLST)
|
gcc -c $(CFLAGS) $(LLST)
|
||||||
test: src/test.c
|
test: src/test.c
|
||||||
|
@ -27,9 +35,6 @@ ui: $(UIF)
|
||||||
gcc -c $(CFLAGS) $(UIF)
|
gcc -c $(CFLAGS) $(UIF)
|
||||||
planner: $(PLF)
|
planner: $(PLF)
|
||||||
gcc -c $(CFLAGS) $(PLF)
|
gcc -c $(CFLAGS) $(PLF)
|
||||||
db: $(DBF)
|
|
||||||
gcc -c $(CFLAGS) $(DBF)
|
|
||||||
|
|
||||||
|
|
||||||
edit:
|
edit:
|
||||||
nvim $(PLF) Makefile $(LLST) src/test.c
|
nvim $(PLF) Makefile $(LLST) src/test.c
|
||||||
|
|
26
src/db.c
26
src/db.c
|
@ -10,21 +10,20 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/************************************************************
|
/************************************************************
|
||||||
*Create a database and handel it
|
*Create a database and handel it
|
||||||
*Created by Jan on 13.12.2024.
|
*Created by Jan on 13.12.2024.
|
||||||
*
|
*
|
||||||
************************************************************/
|
************************************************************/
|
||||||
|
#include "planner.h"
|
||||||
|
#include <sqlite3.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "sqlite3.h"
|
|
||||||
#include "planner.h"
|
|
||||||
|
|
||||||
extern struct llist;
|
extern struct llist;
|
||||||
|
|
||||||
// Initialize a new Database if there no one.
|
// Initialize a new Database if there no one.
|
||||||
void init_db(sqlite3 *db) {
|
void init_db(sqlite3 *db) {
|
||||||
const char *sql_LinkedList =
|
const char *sql_LinkedList = "CREATE TABLE LinkedList ("
|
||||||
"CREATE TABLE LinkedList ("
|
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||||
"data TEXT;)";
|
"data TEXT;)";
|
||||||
|
|
||||||
|
@ -40,14 +39,15 @@ void init_db(sqlite3 *db) {
|
||||||
// node needs to be replaced with the correct name and pointer
|
// node needs to be replaced with the correct name and pointer
|
||||||
void save_node_to_db(sqlite3 *db, Node *node) {
|
void save_node_to_db(sqlite3 *db, Node *node) {
|
||||||
|
|
||||||
char* errmsg = NULL;
|
char *errmsg = NULL;
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
const char* sql = "INSERT INTO LinkedList (id, data) VALUES (?, ?);";
|
const char *sql = "INSERT INTO LinkedList (id, data) VALUES (?, ?);";
|
||||||
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
|
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
|
||||||
fprintf(stderr, "Failed to prepare statement: %s\n", sqlite3_errmsg(db));
|
fprintf(stderr, "Failed to prepare statement: %s\n", sqlite3_errmsg(db));
|
||||||
} else {
|
} else {
|
||||||
sqlite3_bind_int(stmt, 1, node->id); // ? -> node->id
|
sqlite3_bind_int(stmt, 1, node->id); // ? -> node->id
|
||||||
sqlite3_bind_text(stmt, 2, node->data, -1, SQLITE_STATIC); // ? -> node->data
|
sqlite3_bind_text(stmt, 2, node->data, -1,
|
||||||
|
SQLITE_STATIC); // ? -> node->data
|
||||||
if (sqlite3_step(stmt) != SQLITE_DONE) {
|
if (sqlite3_step(stmt) != SQLITE_DONE) {
|
||||||
fprintf(stderr, "Execution failed: %s\n", sqlite3_errmsg(db));
|
fprintf(stderr, "Execution failed: %s\n", sqlite3_errmsg(db));
|
||||||
} else {
|
} else {
|
||||||
|
@ -59,8 +59,8 @@ void save_node_to_db(sqlite3 *db, Node *node) {
|
||||||
|
|
||||||
// save a whole linkedlist in the database
|
// save a whole linkedlist in the database
|
||||||
// node needs to be replaced with the correct name and pointer
|
// node needs to be replaced with the correct name and pointer
|
||||||
void save_linked_list_to_db(sqlite3* db, Node* head) {
|
void save_linked_list_to_db(sqlite3 *db, Node *head) {
|
||||||
Node* current = head;
|
Node *current = head;
|
||||||
while (current != NULL) {
|
while (current != NULL) {
|
||||||
save_node_to_db(db, current);
|
save_node_to_db(db, current);
|
||||||
current = current->next;
|
current = current->next;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue