[db] Upgrade schema to 21.06, change default of query_limit to 0

This commit is contained in:
ejurgensen 2021-01-31 10:27:23 +01:00
parent 79b4a070b0
commit bd91a238ec
6 changed files with 64 additions and 6 deletions

View File

@ -1849,7 +1849,10 @@ db_build_query_clause(struct query_params *qp)
switch (qp->idx_type)
{
case I_FIRST:
qc->index = sqlite3_mprintf("LIMIT %d", qp->limit);
if (qp->limit)
qc->index = sqlite3_mprintf("LIMIT %d", qp->limit);
else
qc->index = sqlite3_mprintf("");
break;
case I_LAST:
@ -2004,7 +2007,7 @@ db_build_query_plitems_smart(struct query_params *qp, struct playlist_info *pli)
if (!qc)
return NULL;
count = sqlite3_mprintf("SELECT COUNT(*) FROM files f %s AND %s LIMIT %d;", qc->where, pli->query, pli->query_limit);
count = sqlite3_mprintf("SELECT COUNT(*) FROM files f %s AND %s LIMIT %d;", qc->where, pli->query, pli->query_limit ? pli->query_limit : -1);
query = sqlite3_mprintf("SELECT f.* FROM files f %s AND %s %s %s;", qc->where, pli->query, qc->order, qc->index);
db_free_query_clause(qc);

View File

@ -255,7 +255,7 @@ struct playlist_info {
uint32_t parent_id; /* Id of parent playlist if the playlist is nested */
uint32_t directory_id; /* Id of directory */
char *query_order; /* order by clause, used by e.g. a smart playlists */
int32_t query_limit; /* limit, used by e.g. smart playlists */
uint32_t query_limit; /* limit, used by e.g. smart playlists */
uint32_t media_kind;
char *artwork_url; /* optional artwork */
uint32_t items; /* number of items (mimc) */

View File

@ -114,7 +114,7 @@
" parent_id INTEGER DEFAULT 0," \
" directory_id INTEGER DEFAULT 0," \
" query_order VARCHAR(1024)," \
" query_limit INTEGER DEFAULT -1," \
" query_limit INTEGER DEFAULT 0," \
" media_kind INTEGER DEFAULT 1," \
" artwork_url VARCHAR(4096) DEFAULT NULL" \
");"

View File

@ -26,7 +26,7 @@
* is a major upgrade. In other words minor version upgrades permit downgrading
* forked-daapd after the database was upgraded. */
#define SCHEMA_VERSION_MAJOR 21
#define SCHEMA_VERSION_MINOR 05
#define SCHEMA_VERSION_MINOR 06
int
db_init_indices(sqlite3 *hdl);

View File

@ -1074,6 +1074,49 @@ static const struct db_upgrade_query db_upgrade_v2105_queries[] =
};
/* ---------------------------- 21.05 -> 21.06 ------------------------------ */
// Reload table, required for changing the default of query_limit from -1 to 0
#define U_V2106_NEW_PLAYLISTS_TABLE \
"CREATE TABLE new_playlists (" \
" id INTEGER PRIMARY KEY NOT NULL," \
" title VARCHAR(255) NOT NULL COLLATE DAAP," \
" type INTEGER NOT NULL," \
" query VARCHAR(1024)," \
" db_timestamp INTEGER NOT NULL," \
" disabled INTEGER DEFAULT 0," \
" path VARCHAR(4096)," \
" idx INTEGER NOT NULL," \
" special_id INTEGER DEFAULT 0," \
" virtual_path VARCHAR(4096)," \
" parent_id INTEGER DEFAULT 0," \
" directory_id INTEGER DEFAULT 0," \
" query_order VARCHAR(1024)," \
" query_limit INTEGER DEFAULT 0," \
" media_kind INTEGER DEFAULT 1," \
" artwork_url VARCHAR(4096) DEFAULT NULL" \
");"
static int
db_upgrade_v2106(sqlite3 *hdl)
{
return db_table_upgrade(hdl, "playlists", U_V2106_NEW_PLAYLISTS_TABLE);
}
// Previously, query_limit had multiple defaults: -1, 0 and UINT32_MAX
#define U_v2106_UPDATE_PLAYLISTS_QUERY_LIMIT \
"UPDATE playlists SET query_limit = 0 WHERE query_limit = -1 OR query_limit = 4294967295;"
#define U_v2106_SCVER_MINOR \
"UPDATE admin SET value = '06' WHERE key = 'schema_version_minor';"
static const struct db_upgrade_query db_upgrade_v2106_queries[] =
{
{ U_v2106_UPDATE_PLAYLISTS_QUERY_LIMIT, "update table playlists query_limit default" },
{ U_v2106_SCVER_MINOR, "set schema_version_minor to 06" },
};
int
db_upgrade(sqlite3 *hdl, int db_ver)
{
@ -1257,6 +1300,18 @@ db_upgrade(sqlite3 *hdl, int db_ver)
if (ret < 0)
return -1;
/* FALLTHROUGH */
case 2105:
ret = db_upgrade_v2106(hdl);
if (ret < 0)
return -1;
ret = db_generic_upgrade(hdl, db_upgrade_v2106_queries, ARRAY_SIZE(db_upgrade_v2106_queries));
if (ret < 0)
return -1;
/* Last case statement is the only one that ends with a break statement! */
break;

View File

@ -73,7 +73,7 @@ scan_smartpl(const char *file, time_t mtime, int dir_id)
swap_pointers(&pli->title, &smartpl.title);
swap_pointers(&pli->query, &smartpl.query_where);
swap_pointers(&pli->query_order, &smartpl.order);
pli->query_limit = smartpl.limit;
pli->query_limit = (smartpl.limit > 0) ? smartpl.limit : 0;
free_smartpl(&smartpl, 1);