From 827921a02810c70a2762e4db37ab731fbd05ce33 Mon Sep 17 00:00:00 2001 From: whatdoineed2do/Ray Date: Tue, 3 Nov 2020 09:11:20 +0000 Subject: [PATCH 1/2] [db] update db_statement_run() to accepts update events like db_query_run() --- src/db.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/db.c b/src/db.c index 8a938c54..fd4ac507 100644 --- a/src/db.c +++ b/src/db.c @@ -1269,9 +1269,10 @@ db_blocking_prepare_v2(const char *query, int len, sqlite3_stmt **stmt, const ch } static int -db_statement_run(sqlite3_stmt *stmt) +db_statement_run(sqlite3_stmt *stmt, short update_events) { int ret; + int changes = 0; #ifdef HAVE_SQLITE3_EXPANDED_SQL char *query; @@ -1296,7 +1297,11 @@ db_statement_run(sqlite3_stmt *stmt) sqlite3_reset(stmt); sqlite3_clear_bindings(stmt); - return (ret == SQLITE_DONE) ? sqlite3_changes(hdl) : -1; + changes = sqlite3_changes(hdl); + if (update_events && changes > 0) + library_update_trigger(update_events); + + return (ret == SQLITE_DONE) ? changes : -1; } @@ -2694,7 +2699,7 @@ db_file_ping_bypath(const char *path, time_t mtime_max) sqlite3_bind_text(db_statements.files_ping, 2, path, -1, SQLITE_STATIC); sqlite3_bind_int64(db_statements.files_ping, 3, (int64_t)mtime_max); - return db_statement_run(db_statements.files_ping); + return db_statement_run(db_statements.files_ping, 0); } void @@ -3092,7 +3097,7 @@ db_file_add(struct media_file_info *mfi) if (ret < 0) return -1; - ret = db_statement_run(db_statements.files_insert); + ret = db_statement_run(db_statements.files_insert, 0); if (ret < 0) return -1; @@ -3120,7 +3125,7 @@ db_file_update(struct media_file_info *mfi) if (ret < 0) return -1; - ret = db_statement_run(db_statements.files_update); + ret = db_statement_run(db_statements.files_update, 0); if (ret < 0) return -1; @@ -3572,7 +3577,7 @@ db_pl_add(struct playlist_info *pli) if (ret < 0) return -1; - ret = db_statement_run(db_statements.playlists_insert); + ret = db_statement_run(db_statements.playlists_insert, 0); if (ret < 0) return -1; @@ -3604,7 +3609,7 @@ db_pl_update(struct playlist_info *pli) if (ret < 0) return -1; - ret = db_statement_run(db_statements.playlists_update); + ret = db_statement_run(db_statements.playlists_update, 0); if (ret < 0) return -1; From 79176956761e4798825988e89f7718f27df922f4 Mon Sep 17 00:00:00 2001 From: whatdoineed2do/Ray Date: Tue, 3 Nov 2020 09:15:21 +0000 Subject: [PATCH 2/2] [db] add LISTENER_DATABASE for db_pl_*() on CRUD --- src/db.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/db.c b/src/db.c index fd4ac507..49f09433 100644 --- a/src/db.c +++ b/src/db.c @@ -3609,7 +3609,7 @@ db_pl_update(struct playlist_info *pli) if (ret < 0) return -1; - ret = db_statement_run(db_statements.playlists_update, 0); + ret = db_statement_run(db_statements.playlists_update, LISTENER_DATABASE); if (ret < 0) return -1; @@ -3624,7 +3624,7 @@ db_pl_add_item_bypath(int plid, const char *path) query = sqlite3_mprintf(Q_TMPL, plid, path); - return db_query_run(query, 1, 0); + return db_query_run(query, 1, LISTENER_DATABASE); #undef Q_TMPL } @@ -3636,7 +3636,7 @@ db_pl_add_item_byid(int plid, int fileid) query = sqlite3_mprintf(Q_TMPL, plid, fileid); - return db_query_run(query, 1, 0); + return db_query_run(query, 1, LISTENER_DATABASE); #undef Q_TMPL } @@ -3651,7 +3651,7 @@ db_pl_clear_items(int id) db_query_run(query, 1, 0); query = sqlite3_mprintf(Q_TMPL_NESTED, id); - db_query_run(query, 1, 0); + db_query_run(query, 1, LISTENER_DATABASE); #undef Q_TMPL_NESTED #undef Q_TMPL_ITEMS } @@ -3672,7 +3672,7 @@ db_pl_delete(int id) query = sqlite3_mprintf(Q_TMPL, id); - ret = db_query_run(query, 1, 0); + ret = db_query_run(query, 1, LISTENER_DATABASE); if (ret < 0) { db_transaction_rollback(); @@ -3685,7 +3685,7 @@ db_pl_delete(int id) // TODO find a cleaner way of identifying tracks added by a playlist query = sqlite3_mprintf(Q_FILES, DATA_KIND_HTTP, id, id); - ret = db_query_run(query, 1, 0); + ret = db_query_run(query, 1, LISTENER_DATABASE); if (ret < 0) { db_transaction_rollback();