Fix video sorting order with regards to published vs added to playlist date
This commit is contained in:
parent
bca774ea2e
commit
81aaff70ac
7
db.cpp
7
db.cpp
|
@ -15,7 +15,10 @@ db_transaction::~db_transaction()
|
||||||
|
|
||||||
std::string get_string(sqlite3_stmt *row, int col)
|
std::string get_string(sqlite3_stmt *row, int col)
|
||||||
{
|
{
|
||||||
return std::string((char*)sqlite3_column_text(row, col));
|
const unsigned char *cp = sqlite3_column_text(row, col);
|
||||||
|
if(cp)
|
||||||
|
return std::string((const char*)cp);
|
||||||
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_int(sqlite3_stmt *row, int col)
|
int get_int(sqlite3_stmt *row, int col)
|
||||||
|
@ -86,7 +89,7 @@ CREATE TABLE user_flags (
|
||||||
name TEXT NOT NULL
|
name TEXT NOT NULL
|
||||||
);
|
);
|
||||||
ALTER TABLE videos ADD COLUMN added_to_playlist TEXT;
|
ALTER TABLE videos ADD COLUMN added_to_playlist TEXT;
|
||||||
UPDATE videos SET added_to_playlist = published, published = "";
|
UPDATE videos SET added_to_playlist = published, published = NULL;
|
||||||
UPDATE settings SET value="2" WHERE key="schema_version";
|
UPDATE settings SET value="2" WHERE key="schema_version";
|
||||||
)";
|
)";
|
||||||
SC(sqlite3_exec(db, sql.c_str(), nullptr, nullptr, nullptr));
|
SC(sqlite3_exec(db, sql.c_str(), nullptr, nullptr, nullptr));
|
||||||
|
|
4
yt.cpp
4
yt.cpp
|
@ -383,7 +383,7 @@ std::vector<Video> Video::get_all_for_channel(const std::string &channel_id)
|
||||||
std::vector<Video> videos;
|
std::vector<Video> videos;
|
||||||
|
|
||||||
sqlite3_stmt *query;
|
sqlite3_stmt *query;
|
||||||
SC(sqlite3_prepare_v2(db, "SELECT * FROM videos WHERE channelId=?1 ORDER BY published DESC, added_to_playlist DESC;", -1, &query, nullptr));
|
SC(sqlite3_prepare_v2(db, "SELECT * FROM videos WHERE channelId=?1 ORDER BY coalesce(published, added_to_playlist) DESC;", -1, &query, nullptr));
|
||||||
SC(sqlite3_bind_text(query, 1, channel_id.c_str(), -1, SQLITE_TRANSIENT));
|
SC(sqlite3_bind_text(query, 1, channel_id.c_str(), -1, SQLITE_TRANSIENT));
|
||||||
|
|
||||||
while(sqlite3_step(query) == SQLITE_ROW) {
|
while(sqlite3_step(query) == SQLITE_ROW) {
|
||||||
|
@ -403,7 +403,7 @@ std::vector<Video> Video::get_all_with_filter(const ChannelFilter &filter)
|
||||||
FROM videos JOIN channels ON videos.channelId = channels.channelId
|
FROM videos JOIN channels ON videos.channelId = channels.channelId
|
||||||
WHERE videos.flags & ?1 = ?2
|
WHERE videos.flags & ?1 = ?2
|
||||||
AND channels.user_flags & ?3 = ?4
|
AND channels.user_flags & ?3 = ?4
|
||||||
ORDER BY published DESC, added_to_playlist DESC;)", -1, &query, nullptr));
|
ORDER BY coalesce(published, added_to_playlist) DESC;)", -1, &query, nullptr));
|
||||||
SC(sqlite3_bind_int(query, 1, filter.video_mask));
|
SC(sqlite3_bind_int(query, 1, filter.video_mask));
|
||||||
SC(sqlite3_bind_int(query, 2, filter.video_value));
|
SC(sqlite3_bind_int(query, 2, filter.video_value));
|
||||||
SC(sqlite3_bind_int(query, 3, filter.user_mask));
|
SC(sqlite3_bind_int(query, 3, filter.user_mask));
|
||||||
|
|
Loading…
Reference in New Issue