From 98a3f80ad38c4bf57b617dd61e41f8c8a0134ff6 Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Sat, 11 Apr 2020 11:01:01 +0200 Subject: [PATCH] deleteid almost done, now need to forbide the deletion of the currently playing kara --- src/database/queue.c | 7 +++---- src/main/lkt.c | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/database/queue.c b/src/database/queue.c index 4f8a4e8d..473a03df 100644 --- a/src/database/queue.c +++ b/src/database/queue.c @@ -307,15 +307,14 @@ bool database_queue_del_id(sqlite3 *db, int id) { static const char *SQL_TEMPLATE = - "WITH before (pos) AS (SELECT position FROM queue_ JOIN queue_state WHERE position < current)" + "WITH before(pos) AS (SELECT position FROM queue_ JOIN queue_state WHERE position < current ORDER BY position DESC LIMIT 1)" "UPDATE queue_state SET current = CASE" - " WHEN (SELECT pos FROM before) IS NULL THEN (SELECT pos FROM queue_ ORDER BY position DESC LIMIT 1)" " WHEN current IS NULL THEN NULL" " ELSE (SELECT pos FROM before)" - "END;" + "END WHERE current >= (SELECT position FROM queue_ WHERE kara_id = %d);" "DELETE FROM queue WHERE kara_id = %d;"; char SQL[LKT_MAX_SQLITE_STATEMENT]; - snprintf(SQL, LKT_MAX_SQLITE_STATEMENT - 1, SQL_TEMPLATE, id); + snprintf(SQL, LKT_MAX_SQLITE_STATEMENT - 1, SQL_TEMPLATE, id, id); SQL[LKT_MAX_SQLITE_STATEMENT - 1] = '\0'; SQLITE_EXEC(db, SQL, error); return true; diff --git a/src/main/lkt.c b/src/main/lkt.c index d6b2e83e..d28fb1a9 100644 --- a/src/main/lkt.c +++ b/src/main/lkt.c @@ -117,6 +117,8 @@ lkt_valid_type(const char *type) return (STR_MATCH(type, "all") || STR_MATCH(type, "any") || STR_MATCH(type, "a") || + STR_MATCH(type, "id") || + STR_MATCH(type, "title") || STR_MATCH(type, "type") || STR_MATCH(type, "cat") || STR_MATCH(type, "category") || -- GitLab