mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-26 23:25:56 -05:00
Merge pull request #320 from chme/admintable
Add primary key column to admin table
This commit is contained in:
commit
7a9bf07d90
16
src/db.c
16
src/db.c
@ -3947,7 +3947,7 @@ db_spotify_files_delete(void)
|
||||
|
||||
/* Admin */
|
||||
int
|
||||
db_admin_add(const char *key, const char *value)
|
||||
db_admin_set(const char *key, const char *value)
|
||||
{
|
||||
#define Q_TMPL "INSERT OR REPLACE INTO admin (key, value) VALUES ('%q', '%q');"
|
||||
char *query;
|
||||
@ -4016,18 +4016,6 @@ db_admin_get(const char *key)
|
||||
#undef Q_TMPL
|
||||
}
|
||||
|
||||
int
|
||||
db_admin_update(const char *key, const char *value)
|
||||
{
|
||||
#define Q_TMPL "UPDATE admin SET value='%q' WHERE key='%q';"
|
||||
char *query;
|
||||
|
||||
query = sqlite3_mprintf(Q_TMPL, value, key);
|
||||
|
||||
return db_query_run(query, 1, 0);
|
||||
#undef Q_TMPL
|
||||
}
|
||||
|
||||
int
|
||||
db_admin_delete(const char *key)
|
||||
{
|
||||
@ -4204,7 +4192,7 @@ queue_inc_version_and_notify()
|
||||
return;
|
||||
}
|
||||
|
||||
ret = db_admin_update("queue_version", version);
|
||||
ret = db_admin_set("queue_version", version);
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_DB, "Error incrementing queue version. Could not update version in admin table: %d\n", queue_version);
|
||||
|
5
src/db.h
5
src/db.h
@ -670,14 +670,11 @@ db_spotify_files_delete(void);
|
||||
|
||||
/* Admin */
|
||||
int
|
||||
db_admin_add(const char *key, const char *value);
|
||||
db_admin_set(const char *key, const char *value);
|
||||
|
||||
char *
|
||||
db_admin_get(const char *key);
|
||||
|
||||
int
|
||||
db_admin_update(const char *key, const char *value);
|
||||
|
||||
int
|
||||
db_admin_delete(const char *key);
|
||||
|
||||
|
@ -25,10 +25,10 @@
|
||||
#include "logger.h"
|
||||
|
||||
|
||||
#define T_ADMIN \
|
||||
"CREATE TABLE IF NOT EXISTS admin(" \
|
||||
" key VARCHAR(32) NOT NULL," \
|
||||
" value VARCHAR(32) NOT NULL" \
|
||||
#define T_ADMIN \
|
||||
"CREATE TABLE IF NOT EXISTS admin(" \
|
||||
" key VARCHAR(32) PRIMARY KEY NOT NULL," \
|
||||
" value VARCHAR(32) NOT NULL" \
|
||||
");"
|
||||
|
||||
#define T_FILES \
|
||||
|
@ -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 19
|
||||
#define SCHEMA_VERSION_MINOR 01
|
||||
#define SCHEMA_VERSION_MINOR 02
|
||||
|
||||
int
|
||||
db_init_indices(sqlite3 *hdl);
|
||||
|
@ -1441,7 +1441,7 @@ db_upgrade_v19(sqlite3 *hdl)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Upgrade from schema v19.00 to v20.00 */
|
||||
/* Upgrade from schema v19.00 to v19.01 */
|
||||
/* Create new table queue for persistent playqueue
|
||||
*/
|
||||
|
||||
@ -1488,6 +1488,46 @@ static const struct db_upgrade_query db_upgrade_v1901_queries[] =
|
||||
{ U_V1901_SCVER_MINOR, "set schema_version_minor to 01" },
|
||||
};
|
||||
|
||||
/* Upgrade from schema v19.01 to v19.02 */
|
||||
/* Set key column as primary key in the admin table
|
||||
*/
|
||||
|
||||
#define U_V1902_CREATE_TABLE_ADMINTMP \
|
||||
"CREATE TEMPORARY TABLE IF NOT EXISTS admin_tmp(" \
|
||||
" key VARCHAR(32) NOT NULL," \
|
||||
" value VARCHAR(32) NOT NULL" \
|
||||
");"
|
||||
#define U_V1902_INSERT_ADMINTMP \
|
||||
"INSERT INTO admin_tmp SELECT * FROM admin;"
|
||||
#define U_V1902_DROP_TABLE_ADMIN \
|
||||
"DROP TABLE admin;"
|
||||
#define U_V1902_CREATE_TABLE_ADMIN \
|
||||
"CREATE TABLE IF NOT EXISTS admin(" \
|
||||
" key VARCHAR(32) PRIMARY KEY NOT NULL," \
|
||||
" value VARCHAR(32) NOT NULL" \
|
||||
");"
|
||||
#define U_V1902_INSERT_ADMIN \
|
||||
"INSERT OR IGNORE INTO admin SELECT * FROM admin_tmp;"
|
||||
#define U_V1902_DROP_TABLE_ADMINTMP \
|
||||
"DROP TABLE admin_tmp;"
|
||||
|
||||
#define U_V1902_SCVER_MAJOR \
|
||||
"UPDATE admin SET value = '19' WHERE key = 'schema_version_major';"
|
||||
#define U_V1902_SCVER_MINOR \
|
||||
"UPDATE admin SET value = '02' WHERE key = 'schema_version_minor';"
|
||||
|
||||
static const struct db_upgrade_query db_upgrade_v1902_queries[] =
|
||||
{
|
||||
{ U_V1902_CREATE_TABLE_ADMINTMP, "create temporary table admin_tmp" },
|
||||
{ U_V1902_INSERT_ADMINTMP, "insert admin_tmp" },
|
||||
{ U_V1902_DROP_TABLE_ADMIN, "drop table admin" },
|
||||
{ U_V1902_CREATE_TABLE_ADMIN, "create table admin" },
|
||||
{ U_V1902_INSERT_ADMIN, "insert admin" },
|
||||
{ U_V1902_DROP_TABLE_ADMINTMP, "drop table admin_tmp" },
|
||||
|
||||
{ U_V1902_SCVER_MAJOR, "set schema_version_major to 19" },
|
||||
{ U_V1902_SCVER_MINOR, "set schema_version_minor to 02" },
|
||||
};
|
||||
|
||||
int
|
||||
db_upgrade(sqlite3 *hdl, int db_ver)
|
||||
@ -1606,6 +1646,11 @@ db_upgrade(sqlite3 *hdl, int db_ver)
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
case 1901:
|
||||
ret = db_generic_upgrade(hdl, db_upgrade_v1902_queries, sizeof(db_upgrade_v1902_queries) / sizeof(db_upgrade_v1902_queries[0]));
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -297,7 +297,7 @@ response_proces(struct http_client_ctx *ctx)
|
||||
if (sk)
|
||||
{
|
||||
DPRINTF(E_LOG, L_LASTFM, "Got session key from LastFM: %s\n", sk);
|
||||
db_admin_add("lastfm_sk", sk);
|
||||
db_admin_set("lastfm_sk", sk);
|
||||
|
||||
if (lastfm_session_key)
|
||||
free(lastfm_session_key);
|
||||
|
Loading…
Reference in New Issue
Block a user