Compare commits
1
Commits
sql
..
d86bcbfcf2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d86bcbfcf2 |
No files matched your search
@@ -13,18 +13,10 @@ CONFIG=src/config.h #config file
|
|||||||
|
|
||||||
|
|
||||||
#targets
|
#targets
|
||||||
debug: db test ui planner iCal config llist
|
debug: test ui planner db 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
|
||||||
@@ -35,6 +27,9 @@ 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
|
||||||
|
|||||||
@@ -10,59 +10,59 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/************************************************************
|
/************************************************************
|
||||||
*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 = "CREATE TABLE LinkedList ("
|
const char *sql_LinkedList =
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
"CREATE TABLE LinkedList ("
|
||||||
"data TEXT;)";
|
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||||
|
"data TEXT;)";
|
||||||
|
|
||||||
// Checks the SQL answer and if it's not ok prints the error code
|
// Checks the SQL answer and if it's not ok prints the error code
|
||||||
char *errmsg = NULL;
|
char *errmsg = NULL;
|
||||||
if (sqlite3_exec(db, sql_LinkedList, NULL, NULL, &errmsg) != SQLITE_OK) {
|
if (sqlite3_exec(db, sql_LinkedList, NULL, NULL, &errmsg) != SQLITE_OK) {
|
||||||
fprintf(stderr, "Error in creation Table: %s\n", errmsg);
|
fprintf(stderr, "Error in creation Table: %s\n", errmsg);
|
||||||
sqlite3_free(errmsg);
|
sqlite3_free(errmsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save a single node of the linkedlist in the database
|
// Save a single node of the 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_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 {
|
|
||||||
sqlite3_bind_int(stmt, 1, node->id); // ? -> node->id
|
|
||||||
sqlite3_bind_text(stmt, 2, node->data, -1,
|
|
||||||
SQLITE_STATIC); // ? -> node->data
|
|
||||||
if (sqlite3_step(stmt) != SQLITE_DONE) {
|
|
||||||
fprintf(stderr, "Execution failed: %s\n", sqlite3_errmsg(db));
|
|
||||||
} else {
|
} else {
|
||||||
printf("Node with ID %d saved.\n", node->id);
|
sqlite3_bind_int(stmt, 1, node->id); // ? -> node->id
|
||||||
|
sqlite3_bind_text(stmt, 2, node->data, -1, SQLITE_STATIC); // ? -> node->data
|
||||||
|
if (sqlite3_step(stmt) != SQLITE_DONE) {
|
||||||
|
fprintf(stderr, "Execution failed: %s\n", sqlite3_errmsg(db));
|
||||||
|
} else {
|
||||||
|
printf("Node with ID %d saved.\n", node->id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
sqlite3_finalize(stmt);
|
||||||
sqlite3_finalize(stmt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-33362
File diff suppressed because it is too large.
Load diff
@@ -3,3 +3,143 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "planner.h" // for subject and event structs
|
#include "planner.h" // for subject and event structs
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "ui.h"
|
||||||
|
|
||||||
|
typedef struct task_elements {
|
||||||
|
char name;
|
||||||
|
int priority;
|
||||||
|
struct task *nextTask;
|
||||||
|
};
|
||||||
|
typedef struct task task_1;
|
||||||
|
typedef struct task* task_ptr;
|
||||||
|
task_ptr firsttask = NULL;
|
||||||
|
|
||||||
|
typedef struct time_elements {
|
||||||
|
int time;
|
||||||
|
struct time *nextTime;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct time time_1;
|
||||||
|
typedef struct time* time_ptr;
|
||||||
|
time_ptr firsttime = NULL;
|
||||||
|
|
||||||
|
void dump_buffer(FILE *fp){
|
||||||
|
int ch;
|
||||||
|
while((ch = fgetc(fp)) != EOF && ch != '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void insertTask(task_ptr newtask)
|
||||||
|
{
|
||||||
|
task_ptr TaskPointer;
|
||||||
|
if (firsttask == NULL){
|
||||||
|
firsttask = newtask;
|
||||||
|
newtask->nextTask ;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
TaskPointer = firsttask;
|
||||||
|
while(TaskPointer->nextTask!=NULL)
|
||||||
|
{
|
||||||
|
TaskPointer = TaskPointer->nextTask;
|
||||||
|
}
|
||||||
|
TaskPointer->nextTask = newtask;
|
||||||
|
newtask ->nextTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void newTask (void)
|
||||||
|
{
|
||||||
|
task_ptr new = malloc(sizeof(task_1));
|
||||||
|
if (new == NULL){
|
||||||
|
printf("Die Liste ist leer?!\n");
|
||||||
|
}
|
||||||
|
printf(" Neues Fach eigeben: ");
|
||||||
|
if(scanf("%d", &newTask)!=1)
|
||||||
|
{
|
||||||
|
dump_buffer(stdin);
|
||||||
|
printf("Fehlerhafte eingabe\n");
|
||||||
|
free(new);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dump_buffer (stdin);
|
||||||
|
insertTask(new);
|
||||||
|
}
|
||||||
|
|
||||||
|
void inserttime(time_ptr newtime)
|
||||||
|
{
|
||||||
|
time_ptr TimePointer;
|
||||||
|
if (firsttime == NULL){
|
||||||
|
firsttime = newtime;
|
||||||
|
newtime->nextTime =NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
TimePointer = firsttime;
|
||||||
|
while(TimePointer->nextTime!=NULL)
|
||||||
|
{
|
||||||
|
TimePointer = TimePointer->nextTime;
|
||||||
|
}
|
||||||
|
TimePointer->nextTime = newtime;
|
||||||
|
newtime ->nextTime = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void newTime(void)
|
||||||
|
{
|
||||||
|
time_ptr newtime = malloc(sizeof(task_1));
|
||||||
|
if (newtime == NULL){
|
||||||
|
printf("Die Liste ist leer?!\n");
|
||||||
|
}
|
||||||
|
printf(" Neue Zeit eigneben: ");
|
||||||
|
if(scanf("%d",&newTime)!=1)
|
||||||
|
{
|
||||||
|
dump_buffer(stdin);
|
||||||
|
printf("Fehlerhafte eingabe\n");
|
||||||
|
free(newtime);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dump_buffer (stdin);
|
||||||
|
inserttime(newtime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tasklisting(void){
|
||||||
|
task_ptr TaskPointer = firsttask;
|
||||||
|
printf("Erfasste Fächer:\n");
|
||||||
|
while(TaskPointer!=NULL)
|
||||||
|
printf("\t->%d\n", TaskPointer->name);
|
||||||
|
TaskPointer = TaskPointer->nextTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int choice = 0, i = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
printf(" -1- Neues Fach eingeben\n");
|
||||||
|
printf(" -2- Verfuegbare Zeit eingeben\n");
|
||||||
|
printf(" -3- Alle vorhandenen Faecher aufliesten\n");
|
||||||
|
printf(" -4- Planer beenden\n");
|
||||||
|
if( scanf("%d", &choice) != 1){
|
||||||
|
printf("Falsche Eingabe\n");};
|
||||||
|
choice = 0;
|
||||||
|
dump_buffer(stdin);
|
||||||
|
|
||||||
|
switch (choice)
|
||||||
|
{
|
||||||
|
case 1: newTask();break;
|
||||||
|
case 2: newTime();break;
|
||||||
|
case 3: if( firsttask == NULL){
|
||||||
|
printf("Die Liste ist leer");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
tasklisting();
|
||||||
|
}break;
|
||||||
|
}
|
||||||
|
}while (choice != 4);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user