]> uap-core.de Git - note.git/commitdiff
add note_store_notebook_swap_position_async
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 27 Jul 2025 11:03:24 +0000 (13:03 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 27 Jul 2025 11:03:24 +0000 (13:03 +0200)
application/store.c
application/store.h

index d774d84b3f68241c0ef479f2c646061cb70edf69..18a09a026fa156f47269d24bd4ced97534ca3d15 100644 (file)
     "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);
 }
index a319dca82945fdf49ae25d09b97733c14a1c899b..d1ff672498213687c43d2368bd9c5c82c29ff5a5 100644 (file)
@@ -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,