adds the remove function'

This commit is contained in:
SuperNovaa41 2025-03-07 01:35:20 -05:00
parent 3513858264
commit 3d6f78e29a
2 changed files with 29 additions and 1 deletions

View File

@ -138,8 +138,33 @@ void add_to_db(book_t* book, sqlite3* db)
}
sqlite3_close(db);
free(cmd);
}
#undef INSERT_STR
#define DEL_STR "DELETE FROM books WHERE id = "
void remove_from_db(int id, sqlite3* db)
{
int err;
char *cmd, *err_msg;
open_db(&db);
cmd = malloc(sizeof(char) * (strlen(DEL_STR) + 1));
snprintf(cmd, strlen(DEL_STR), "%s", DEL_STR);
add_int_entry(&cmd, id, true);
err = sqlite3_exec(db, cmd, 0, 0, &err_msg);
if (err != SQLITE_OK) {
fprintf(stderr, "sqlite3_exec: %s\n", err_msg);
sqlite3_free(err_msg);
sqlite3_close(db);
exit(EXIT_FAILURE);
}
sqlite3_close(db);
free(cmd);
}
#undef INSERT_STR
#undef DEL_STR

View File

@ -16,4 +16,7 @@ void setup_db(sqlite3* db);
void add_to_db(book_t* book, sqlite3* db);
void remove_from_db(int id, sqlite3* db);
#endif