Added active_id increment in schema
This commit is contained in:
parent
586786ff6c
commit
09492950b8
@ -245,7 +245,7 @@ int update_task_status(sqlite3 *db, int argc, char** argv){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
checksqlerr(rc, "broken in add_new_task");
|
checksqlerr(rc, "broken in update_task_status");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -265,7 +265,7 @@ int del_task(sqlite3 *db, int argc, char** argv){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
checksqlerr(rc, "broken in add_new_task");
|
checksqlerr(rc, "broken in del_task");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,8 +275,8 @@ int del_task(sqlite3 *db, int argc, char** argv){
|
|||||||
int add_new_task(sqlite3 *db, int argc, char** argv){
|
int add_new_task(sqlite3 *db, int argc, char** argv){
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
char* table = "tasks";
|
char* table = "tasks";
|
||||||
char* title;
|
char* title = NULL;
|
||||||
char* due_date;
|
char* due_date = NULL;
|
||||||
char* colnames = "(title, due_date)";
|
char* colnames = "(title, due_date)";
|
||||||
char values[100];
|
char values[100];
|
||||||
sqlite3_stmt* out_stmt;
|
sqlite3_stmt* out_stmt;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
CREATE TABLE tasks(
|
CREATE TABLE tasks(
|
||||||
task_id INTEGER PRIMARY KEY,
|
task_id INTEGER PRIMARY KEY,
|
||||||
title TEXT NOT NULL,
|
title TEXT NOT NULL UNIQUE,
|
||||||
active_id INTEGER UNIQUE,
|
active_id INTEGER UNIQUE,
|
||||||
status TEXT NOT NULL DEFAULT 'backlog',
|
status TEXT NOT NULL DEFAULT 'backlog',
|
||||||
creation_date DATE DEFAULT (date('now')),
|
creation_date DATE DEFAULT (date('now')),
|
||||||
@ -11,6 +11,17 @@ CREATE TABLE tasks(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- Basically when we add a new task the active id is set
|
||||||
|
-- but when a task is done we want it to be able to be null so we need to increment
|
||||||
|
-- COALESCE is a cool function that returns the first non-null argument which takes care of empty
|
||||||
|
-- active task list
|
||||||
|
CREATE TRIGGER autoinc_active_id
|
||||||
|
AFTER INSERT ON tasks
|
||||||
|
BEGIN
|
||||||
|
UPDATE tasks SET active_id = (SELECT COALESCE((SELECT MAX(active_id) FROM tasks) + 1, 1)) WHERE task_id=NEW.task_id;
|
||||||
|
|
||||||
|
END;
|
||||||
|
|
||||||
CREATE TABLE entries(
|
CREATE TABLE entries(
|
||||||
entry_id INTEGER PRIMARY KEY,
|
entry_id INTEGER PRIMARY KEY,
|
||||||
task_id INTEGER NOT NULL REFERENCES tasks(task_id),
|
task_id INTEGER NOT NULL REFERENCES tasks(task_id),
|
||||||
|
Loading…
Reference in New Issue
Block a user