Skip to content

Commit a1cbfa1

Browse files
committed
Merge branch 'sticker_set' of https://github.com/jcorporation/MPD
2 parents e06d775 + 015870a commit a1cbfa1

File tree

2 files changed

+13
-55
lines changed

2 files changed

+13
-55
lines changed

src/sticker/Database.cxx

+12-53
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ enum sticker_sql_find {
3737
enum sticker_sql {
3838
STICKER_SQL_GET,
3939
STICKER_SQL_LIST,
40-
STICKER_SQL_UPDATE,
41-
STICKER_SQL_INSERT,
40+
STICKER_SQL_SET,
4241
STICKER_SQL_DELETE,
4342
STICKER_SQL_DELETE_VALUE,
4443
STICKER_SQL_DISTINCT_TYPE_URI,
@@ -88,10 +87,10 @@ static constexpr auto sticker_sql = std::array {
8887
"SELECT value FROM sticker WHERE type=? AND uri=? AND name=?",
8988
//[STICKER_SQL_LIST] =
9089
"SELECT name,value FROM sticker WHERE type=? AND uri=?",
91-
//[STICKER_SQL_UPDATE] =
92-
"UPDATE sticker SET value=? WHERE type=? AND uri=? AND name=?",
93-
//[STICKER_SQL_INSERT] =
94-
"INSERT INTO sticker(type,uri,name,value) VALUES(?, ?, ?, ?)",
90+
//[STICKER_SQL_SET] =
91+
"INSERT INTO sticker(type, uri, name, value) VALUES(?, ?, ?, ?) "
92+
"ON CONFLICT(type, uri, name) DO "
93+
"UPDATE set value = ?",
9594
//[STICKER_SQL_DELETE] =
9695
"DELETE FROM sticker WHERE type=? AND uri=?",
9796
//[STICKER_SQL_DELETE_VALUE] =
@@ -227,45 +226,21 @@ StickerDatabase::ListValues(std::map<std::string, std::string, std::less<>> &tab
227226
});
228227
}
229228

230-
bool
231-
StickerDatabase::UpdateValue(const char *type, const char *uri,
232-
const char *name, const char *value)
229+
void
230+
StickerDatabase::StoreValue(const char *type, const char *uri,
231+
const char *name, const char *value)
233232
{
234-
sqlite3_stmt *const s = stmt[STICKER_SQL_UPDATE];
235-
236233
assert(type != nullptr);
237234
assert(uri != nullptr);
238235
assert(name != nullptr);
239-
assert(*name != 0);
240236
assert(value != nullptr);
241237

242-
BindAll(s, value, type, uri, name);
243-
244-
AtScopeExit(s) {
245-
sqlite3_reset(s);
246-
sqlite3_clear_bindings(s);
247-
};
248-
249-
bool modified = ExecuteModified(s);
250-
251-
if (modified)
252-
idle_add(IDLE_STICKER);
253-
return modified;
254-
}
255-
256-
void
257-
StickerDatabase::InsertValue(const char *type, const char *uri,
258-
const char *name, const char *value)
259-
{
260-
sqlite3_stmt *const s = stmt[STICKER_SQL_INSERT];
238+
if (StringIsEmpty(name))
239+
return;
261240

262-
assert(type != nullptr);
263-
assert(uri != nullptr);
264-
assert(name != nullptr);
265-
assert(*name != 0);
266-
assert(value != nullptr);
241+
sqlite3_stmt *const s = stmt[STICKER_SQL_SET];
267242

268-
BindAll(s, type, uri, name, value);
243+
BindAll(s, type, uri, name, value, value);
269244

270245
AtScopeExit(s) {
271246
sqlite3_reset(s);
@@ -276,22 +251,6 @@ StickerDatabase::InsertValue(const char *type, const char *uri,
276251
idle_add(IDLE_STICKER);
277252
}
278253

279-
void
280-
StickerDatabase::StoreValue(const char *type, const char *uri,
281-
const char *name, const char *value)
282-
{
283-
assert(type != nullptr);
284-
assert(uri != nullptr);
285-
assert(name != nullptr);
286-
assert(value != nullptr);
287-
288-
if (StringIsEmpty(name))
289-
return;
290-
291-
if (!UpdateValue(type, uri, name, value))
292-
InsertValue(type, uri, name, value);
293-
}
294-
295254
void
296255
StickerDatabase::IncValue(const char *type, const char *uri,
297256
const char *name, const char *value)

src/sticker/Database.hxx

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class StickerDatabase {
4343
enum SQL {
4444
SQL_GET,
4545
SQL_LIST,
46-
SQL_UPDATE,
47-
SQL_INSERT,
46+
SQL_SET,
4847
SQL_DELETE,
4948
SQL_DELETE_VALUE,
5049
SQL_DISTINCT_TYPE_URI,

0 commit comments

Comments
 (0)