Implement done command
This commit is contained in:
parent
54ec5262d3
commit
22cd6a69da
36
src/db.c
36
src/db.c
@ -95,9 +95,41 @@ int add_task(task_t t) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int update_task(task_t t) { //TODO
|
||||
(void)t;
|
||||
int update_task(task_t t) {
|
||||
sqlite3* db = get_db();
|
||||
sqlite3_stmt* stmt;
|
||||
|
||||
int ret = sqlite3_prepare_v2(db, "UPDATE tasks SET text=?2, done=?3, due_to=?4 WHERE id=?1;", -1, &stmt, 0);
|
||||
|
||||
if (ret != SQLITE_OK) {
|
||||
printf("(get_task) failure fetching data\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char str_id[10];
|
||||
sprintf(str_id, "%d", (int)t.id);
|
||||
sqlite3_bind_text(stmt, 1, str_id, -1, SQLITE_STATIC);
|
||||
sqlite3_bind_text(stmt, 2, t.text, -1, SQLITE_STATIC);
|
||||
|
||||
char str_done[2]; // Just a boolean
|
||||
sprintf(str_done, "%d", t.done);
|
||||
sqlite3_bind_text(stmt, 3, str_done, -1, SQLITE_STATIC);
|
||||
|
||||
char str_due_to[15];
|
||||
sprintf(str_due_to, "%ld", t.due_to);
|
||||
sqlite3_bind_text(stmt, 4, str_due_to, -1, SQLITE_STATIC);
|
||||
|
||||
|
||||
ret = sqlite3_step(stmt);
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
sqlite3_close(db);
|
||||
|
||||
if (ret != SQLITE_DONE) {
|
||||
printf("Return value: %d\n", ret);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user