Merge branch 'sticker_set' of https://github.com/jcorporation/MPD
This commit is contained in:
commit
a1cbfa1623
src/sticker
@ -37,8 +37,7 @@ enum sticker_sql_find {
|
|||||||
enum sticker_sql {
|
enum sticker_sql {
|
||||||
STICKER_SQL_GET,
|
STICKER_SQL_GET,
|
||||||
STICKER_SQL_LIST,
|
STICKER_SQL_LIST,
|
||||||
STICKER_SQL_UPDATE,
|
STICKER_SQL_SET,
|
||||||
STICKER_SQL_INSERT,
|
|
||||||
STICKER_SQL_DELETE,
|
STICKER_SQL_DELETE,
|
||||||
STICKER_SQL_DELETE_VALUE,
|
STICKER_SQL_DELETE_VALUE,
|
||||||
STICKER_SQL_DISTINCT_TYPE_URI,
|
STICKER_SQL_DISTINCT_TYPE_URI,
|
||||||
@ -88,10 +87,10 @@ static constexpr auto sticker_sql = std::array {
|
|||||||
"SELECT value FROM sticker WHERE type=? AND uri=? AND name=?",
|
"SELECT value FROM sticker WHERE type=? AND uri=? AND name=?",
|
||||||
//[STICKER_SQL_LIST] =
|
//[STICKER_SQL_LIST] =
|
||||||
"SELECT name,value FROM sticker WHERE type=? AND uri=?",
|
"SELECT name,value FROM sticker WHERE type=? AND uri=?",
|
||||||
//[STICKER_SQL_UPDATE] =
|
//[STICKER_SQL_SET] =
|
||||||
"UPDATE sticker SET value=? WHERE type=? AND uri=? AND name=?",
|
"INSERT INTO sticker(type, uri, name, value) VALUES(?, ?, ?, ?) "
|
||||||
//[STICKER_SQL_INSERT] =
|
"ON CONFLICT(type, uri, name) DO "
|
||||||
"INSERT INTO sticker(type,uri,name,value) VALUES(?, ?, ?, ?)",
|
"UPDATE set value = ?",
|
||||||
//[STICKER_SQL_DELETE] =
|
//[STICKER_SQL_DELETE] =
|
||||||
"DELETE FROM sticker WHERE type=? AND uri=?",
|
"DELETE FROM sticker WHERE type=? AND uri=?",
|
||||||
//[STICKER_SQL_DELETE_VALUE] =
|
//[STICKER_SQL_DELETE_VALUE] =
|
||||||
@ -227,55 +226,6 @@ StickerDatabase::ListValues(std::map<std::string, std::string, std::less<>> &tab
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
StickerDatabase::UpdateValue(const char *type, const char *uri,
|
|
||||||
const char *name, const char *value)
|
|
||||||
{
|
|
||||||
sqlite3_stmt *const s = stmt[STICKER_SQL_UPDATE];
|
|
||||||
|
|
||||||
assert(type != nullptr);
|
|
||||||
assert(uri != nullptr);
|
|
||||||
assert(name != nullptr);
|
|
||||||
assert(*name != 0);
|
|
||||||
assert(value != nullptr);
|
|
||||||
|
|
||||||
BindAll(s, value, type, uri, name);
|
|
||||||
|
|
||||||
AtScopeExit(s) {
|
|
||||||
sqlite3_reset(s);
|
|
||||||
sqlite3_clear_bindings(s);
|
|
||||||
};
|
|
||||||
|
|
||||||
bool modified = ExecuteModified(s);
|
|
||||||
|
|
||||||
if (modified)
|
|
||||||
idle_add(IDLE_STICKER);
|
|
||||||
return modified;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
StickerDatabase::InsertValue(const char *type, const char *uri,
|
|
||||||
const char *name, const char *value)
|
|
||||||
{
|
|
||||||
sqlite3_stmt *const s = stmt[STICKER_SQL_INSERT];
|
|
||||||
|
|
||||||
assert(type != nullptr);
|
|
||||||
assert(uri != nullptr);
|
|
||||||
assert(name != nullptr);
|
|
||||||
assert(*name != 0);
|
|
||||||
assert(value != nullptr);
|
|
||||||
|
|
||||||
BindAll(s, type, uri, name, value);
|
|
||||||
|
|
||||||
AtScopeExit(s) {
|
|
||||||
sqlite3_reset(s);
|
|
||||||
sqlite3_clear_bindings(s);
|
|
||||||
};
|
|
||||||
|
|
||||||
ExecuteCommand(s);
|
|
||||||
idle_add(IDLE_STICKER);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
StickerDatabase::StoreValue(const char *type, const char *uri,
|
StickerDatabase::StoreValue(const char *type, const char *uri,
|
||||||
const char *name, const char *value)
|
const char *name, const char *value)
|
||||||
@ -288,8 +238,17 @@ StickerDatabase::StoreValue(const char *type, const char *uri,
|
|||||||
if (StringIsEmpty(name))
|
if (StringIsEmpty(name))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!UpdateValue(type, uri, name, value))
|
sqlite3_stmt *const s = stmt[STICKER_SQL_SET];
|
||||||
InsertValue(type, uri, name, value);
|
|
||||||
|
BindAll(s, type, uri, name, value, value);
|
||||||
|
|
||||||
|
AtScopeExit(s) {
|
||||||
|
sqlite3_reset(s);
|
||||||
|
sqlite3_clear_bindings(s);
|
||||||
|
};
|
||||||
|
|
||||||
|
ExecuteCommand(s);
|
||||||
|
idle_add(IDLE_STICKER);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -43,8 +43,7 @@ class StickerDatabase {
|
|||||||
enum SQL {
|
enum SQL {
|
||||||
SQL_GET,
|
SQL_GET,
|
||||||
SQL_LIST,
|
SQL_LIST,
|
||||||
SQL_UPDATE,
|
SQL_SET,
|
||||||
SQL_INSERT,
|
|
||||||
SQL_DELETE,
|
SQL_DELETE,
|
||||||
SQL_DELETE_VALUE,
|
SQL_DELETE_VALUE,
|
||||||
SQL_DISTINCT_TYPE_URI,
|
SQL_DISTINCT_TYPE_URI,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user