diff --git a/inc/lektor/database.h b/inc/lektor/database.h index 63f6ccf4d9d1feff8478f41e18473b8858f73311..4da2d086ac7ee9ca666078a5a341594198ef4f21 100644 --- a/inc/lektor/database.h +++ b/inc/lektor/database.h @@ -66,7 +66,7 @@ bool database_queue_stop (volatile sqlite3 *db); /* A search callback to be called after each matched row */ struct lkt_callback { - bool (*call)(void *args, int id, int id_len, const char *sql_row); + bool (*call)(void *args, int pos, int pos_len, int id, int id_len, const char *sql_row); struct lkt_state *srv; size_t c; int iterations; diff --git a/src/commands.c b/src/commands.c index 22294dc4bcdb10b79164a704c5dfc3805d91baf2..2b1fa4eeed0b61bdff208858576626a5c33b3f49 100644 --- a/src/commands.c +++ b/src/commands.c @@ -375,12 +375,12 @@ command_noidle(struct lkt_state *srv, size_t c) /* Functions for the searchadd and the search mpd commands */ bool -lkt_callback_send_row_v1(void *_args, int id, int id_len, const char *sql_row) +lkt_callback_send_row_v1(void *_args, int pos_len, int pos, int id, int id_len, const char *sql_row) { struct lkt_callback *args = (struct lkt_callback *) _args; struct lkt_message *out; out = lkt_message_new(); - out->data_len = snprintf(out->data, LKT_MESSAGE_MAX, "%*d %s\n", id_len, id, sql_row); + out->data_len = snprintf(out->data, LKT_MESSAGE_MAX, "%*d: %*d %s\n", pos_len, pos, id_len, id, sql_row); lkt_state_send(args->srv, args->c, out); return true; } @@ -391,7 +391,6 @@ lkt_callback_send_row_v2(struct lkt_state *srv, size_t c, int id, int id_len, co struct lkt_message *out = lkt_message_new(); out->data_len = snprintf(out->data, LKT_MESSAGE_MAX, "%*d %s\n", id_len, id, sql_row); lkt_state_send(srv, c, out); - printf("TOTO\n"); return true; } diff --git a/src/database/queue.c b/src/database/queue.c index a6371ad6cd69db3e5dddc93a96869b0275bb3f68..98f4c7bbcb4f7adf5947305c06e6bd9c601cd1f4 100644 --- a/src/database/queue.c +++ b/src/database/queue.c @@ -591,13 +591,13 @@ database_queue_list(volatile sqlite3 *db, size_t from, size_t to, struct lkt_cal { const char *SQL_STMT = "WITH content AS (" - " SELECT kara.id AS id, string, LENGTH(CAST(kara.id AS TEXT)) AS len" + " SELECT kara.id AS id, string, LENGTH(CAST(kara.id AS TEXT)) AS len, position, LENGTH(CAST(position AS TEXT)) AS pos_len" " FROM queue" " JOIN kara ON kara_id = kara.id" " WHERE position >= ? AND position <= ?" " GROUP BY position ORDER BY position ASC, priority DESC)" - "SELECT id, string, (SELECT MAX(len) FROM content) FROM content;"; - int code, id, id_len; + "SELECT id, string, (SELECT MAX(len) FROM content), position, (SELECT MAX(pos_len) FROM content) FROM content;"; + int code, id, id_len, pos, pos_len; const char *row; bool ret = false; sqlite3_stmt *stmt; @@ -613,8 +613,10 @@ database_queue_list(volatile sqlite3 *db, size_t from, size_t to, struct lkt_cal id = sqlite3_column_int(stmt, 0); row = (const char *) sqlite3_column_text(stmt, 1); id_len = sqlite3_column_int(stmt, 2); + pos = sqlite3_column_int(stmt, 3); + pos_len = sqlite3_column_int(stmt, 4); ++(callback->iterations); - if (callback->call(callback, id, id_len, row)) + if (callback->call(callback, pos_len, pos, id, id_len, row)) continue; else break;