@@ -37,8 +37,7 @@ enum sticker_sql_find {
37
37
enum sticker_sql {
38
38
STICKER_SQL_GET,
39
39
STICKER_SQL_LIST,
40
- STICKER_SQL_UPDATE,
41
- STICKER_SQL_INSERT,
40
+ STICKER_SQL_SET,
42
41
STICKER_SQL_DELETE,
43
42
STICKER_SQL_DELETE_VALUE,
44
43
STICKER_SQL_DISTINCT_TYPE_URI,
@@ -88,10 +87,10 @@ static constexpr auto sticker_sql = std::array {
88
87
" SELECT value FROM sticker WHERE type=? AND uri=? AND name=?" ,
89
88
// [STICKER_SQL_LIST] =
90
89
" 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 = ? " ,
95
94
// [STICKER_SQL_DELETE] =
96
95
" DELETE FROM sticker WHERE type=? AND uri=?" ,
97
96
// [STICKER_SQL_DELETE_VALUE] =
@@ -227,45 +226,21 @@ StickerDatabase::ListValues(std::map<std::string, std::string, std::less<>> &tab
227
226
});
228
227
}
229
228
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)
233
232
{
234
- sqlite3_stmt *const s = stmt[STICKER_SQL_UPDATE];
235
-
236
233
assert (type != nullptr );
237
234
assert (uri != nullptr );
238
235
assert (name != nullptr );
239
- assert (*name != 0 );
240
236
assert (value != nullptr );
241
237
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 ;
261
240
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];
267
242
268
- BindAll (s, type, uri, name, value);
243
+ BindAll (s, type, uri, name, value, value );
269
244
270
245
AtScopeExit (s) {
271
246
sqlite3_reset (s);
@@ -276,22 +251,6 @@ StickerDatabase::InsertValue(const char *type, const char *uri,
276
251
idle_add (IDLE_STICKER);
277
252
}
278
253
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
-
295
254
void
296
255
StickerDatabase::IncValue (const char *type, const char *uri,
297
256
const char *name, const char *value)
0 commit comments