Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 2a7f7198 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

DB: Add the function to back propagate the priority

Back propagate the priority from the currently playing to the next kara
with a priority superior to 1 (a prioritised kara).

This is done to not disorder the queue on queue_prev with the resequence
operation on the queue.
parent 36099eeb
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!173Update priority on next/prev operations
...@@ -41,6 +41,15 @@ ...@@ -41,6 +41,15 @@
} \ } \
} }
#define SQLITE_BIND_INT64(db, stmt, pos, integer, error) \
{ \
if (sqlite3_bind_int64(stmt, pos, integer) != SQLITE_OK) { \
___LOCAL_DEBUG("Failed to bind int %d at pos %d: %s", integer, pos, \
sqlite3_errmsg((sqlite3 *)db)); \
goto error; \
} \
}
#define SQLITE_STEP(db, stmt, code, error) \ #define SQLITE_STEP(db, stmt, code, error) \
{ \ { \
if (sqlite3_step(stmt) != code) { \ if (sqlite3_step(stmt) != code) { \
......
...@@ -533,9 +533,66 @@ database_queue_skip_current(lkt_db *db, char filepath[PATH_MAX]) ...@@ -533,9 +533,66 @@ database_queue_skip_current(lkt_db *db, char filepath[PATH_MAX])
* included. It only makes sense to call that function from the * included. It only makes sense to call that function from the
* 'database_queue_prev' function. */ * 'database_queue_prev' function. */
PRIVATE_FUNCTION bool PRIVATE_FUNCTION bool
___database_back_propagate_priority(UNUSED lkt_db *db) ___database_back_propagate_priority(lkt_db *db)
{ {
/* Get the next kara with priority > 1 after the current in the queue */
static const char *SQL_GET_POS_WITH_PRIO_SUP_1 =
"SELECT position, priority"
" FROM queue"
" JOIN queue_state ON"
" queue_state.current <= queue.position AND queue.priority > 1"
" ORDER BY position ASC LIMIT 1;";
/* Get the currently playing kara */
static const char *SQL_GET_CURRENT = "SELECT current FROM queue_state LIMIT 1;";
/* Apply priority to range */
static const char *SQL_APPLY_PRIORITY_TO_RANGE =
"UPDATE queue SET priority = ? WHERE position >= ? AND position <= ?;";
int64_t currently_playing_position = 0;
int64_t next_kara_with_prio_sup_1 = 0;
int priority_to_back_propagate = 1;
sqlite3_stmt *stmt = NULL;
/* Currently playing position */
SQLITE_PREPARE(db, stmt, SQL_GET_CURRENT, not_playing_or_no_need_to_back_propagate);
SQLITE_STEP_ROW(db, stmt, not_playing_or_no_need_to_back_propagate);
currently_playing_position = sqlite3_column_int64(stmt, 1);
sqlite3_finalize(stmt);
/* Next kara with priority > 1 */
SQLITE_PREPARE(db, stmt, SQL_GET_POS_WITH_PRIO_SUP_1, error);
SQLITE_STEP_ROW(db, stmt, error);
next_kara_with_prio_sup_1 = sqlite3_column_int64(stmt, 1);
priority_to_back_propagate = sqlite3_column_int(stmt, 2);
sqlite3_finalize(stmt);
/* Back-propagate the priority */
SQLITE_PREPARE(db, stmt, SQL_APPLY_PRIORITY_TO_RANGE, error);
SQLITE_BIND_INT(db, stmt, 0, priority_to_back_propagate, error);
SQLITE_BIND_INT64(db, stmt, 1, currently_playing_position, error);
SQLITE_BIND_INT64(db, stmt, 2, next_kara_with_prio_sup_1, error);
SQLITE_STEP_DONE(db, stmt, error);
sqlite3_finalize(stmt);
/* Everything whent OK */
return true;
/* An error occured, free the sqlite statement */
error:
if (stmt != NULL)
sqlite3_finalize(stmt);
return false; return false;
/* Not a failure and no operations needed:
* - If not playing no need to back propagate.
* - No kara with priority > 1 after the playing one, no need to
* backpropagate the priority. */
not_playing_or_no_need_to_back_propagate:
if (stmt != NULL)
sqlite3_finalize(stmt);
return true;
} }
bool bool
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter