From 5a076e0edf5ebe4904e19a89d1f8c67ef1b450d9 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sun, 27 Jul 2025 13:03:24 +0200 Subject: [PATCH] add note_store_notebook_swap_position_async --- application/store.c | 36 +++++++++++++++++++++++++++++++++++- application/store.h | 2 +- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/application/store.c b/application/store.c index d774d84..18a09a0 100644 --- a/application/store.c +++ b/application/store.c @@ -105,6 +105,13 @@ "insert into notebooks(resource_id, position) " \ "(?, (select coalesce(max(position), 0)+1 from notebooks)) returning notebook_id;" +#define SQL_NOTEBOOK_SWAP_POS \ + "update notebooks set position = case notebook_id " \ + "when ?1 then (select position from notebooks where notebook_id = ?2) " \ + "when ?2 then (select position from notebooks where notebook_id = ?1) " \ + "end " \ + "where notebook_id in (?1, ?2);" + static DBUConnection *connection; static UiThreadpool *queue; @@ -950,5 +957,32 @@ void note_store_delete_collection_and_move_children_async( job->error = 0; job->id1 = res->resource_id; job->id2 = new_parent_id; - ui_threadpool_job(queue, obj, (ui_threadfunc)qthr_delete_empty_collection, job, (ui_callback)uithr_execjob_finished, job); + ui_threadpool_job(queue, obj, (ui_threadfunc)qthr_delete_collection_and_move_children, job, (ui_callback)uithr_execjob_finished, job); +} + +static void qthr_store_notebook_swap_position(ExecJob *job) { + DBUQuery *q0 = connection->createQuery(connection, NULL); + dbuQuerySetSQL(q0, SQL_RESOURCE_UPDATE_PARENT); + dbuQuerySetParamInt64(q0, 1, job->id1); + dbuQuerySetParamInt64(q0, 2, job->id2); + if(dbuQueryExec(q0)) { + job->error = 1; + } + dbuQueryFree(q0); +} + +void note_store_notebook_swap_position_async( + UiObject *obj, + Notebook *nb1, + Notebook *nb2, + execresult_func resultcb, + void *userdata) +{ + ExecJob *job = malloc(sizeof(ExecJob)); + job->resultcb = resultcb; + job->userdata = userdata; + job->error = 0; + job->id1 = nb1->notebook_id; + job->id2 = nb2->notebook_id; + ui_threadpool_job(queue, obj, (ui_threadfunc)qthr_store_notebook_swap_position, job, (ui_callback)uithr_execjob_finished, job); } diff --git a/application/store.h b/application/store.h index a319dca..d1ff672 100644 --- a/application/store.h +++ b/application/store.h @@ -113,7 +113,7 @@ void note_store_delete_collection_and_move_children_async( execresult_func resultcb, void *userdata); -void note_store_notebook_swap_position( +void note_store_notebook_swap_position_async( UiObject *obj, Notebook *nb1, Notebook *nb2, -- 2.47.3