Fix query for getting task from database.

This commit is contained in:
nisakov 2019-02-27 02:40:23 +03:00
parent 514b3c0d1f
commit 15ed05d39f
1 changed files with 2 additions and 2 deletions

View File

@ -167,9 +167,9 @@ func GetTaskByID(username string, id int) (types.Context, error) {
var tasks []types.Task var tasks []types.Task
var task types.Task var task types.Task
getTaskSQL := "select t.id, t.title, t.content, t.priority, t.hide, c.name from task t join user u left outer join category c where c.id = t.cat_id and t.user_id=u.id and t.id=? and u.username=? union select t.id, t.title, t.content, t.priority, t.hide, 'UNCATEGORIZED' from task t join user u where t.user_id=u.id and t.cat_id=0 ;" getTaskSQL := "select t.id, t.title, t.content, t.priority, t.hide, c.name from task t join user u left outer join category c where c.id = t.cat_id and t.user_id=u.id and t.id=? and u.username=? union select t.id, t.title, t.content, t.priority, t.hide, 'UNCATEGORIZED' from task t join user u where t.user_id=u.id and t.cat_id=0 and t.id=? and u.username=?;"
rows := database.query(getTaskSQL, id, username) rows := database.query(getTaskSQL, id, username, id, username)
defer rows.Close() defer rows.Close()
if rows.Next() { if rows.Next() {
err := rows.Scan(&task.Id, &task.Title, &task.Content, &task.Priority, &task.IsHidden, &task.Category) err := rows.Scan(&task.Id, &task.Title, &task.Content, &task.Priority, &task.IsHidden, &task.Category)