]> uap-core.de Git - note.git/commitdiff
also insert row into notebooks table when creating a new notebook
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 21 May 2025 19:49:08 +0000 (21:49 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 21 May 2025 19:49:08 +0000 (21:49 +0200)
application/store.c

index 7a271797d9f34fd77fc495c52256d5da49b8e956..21c62f3a27b6978b371adcd55c3ecd0708444aa4 100644 (file)
     "inner join resources r on a.attachment_resource_id = r.resource_id " \
     "where parent_resource_id = ? order by attachment_id;"
 
-#define SQL_NOTEBOOK_NEW \
+#define SQL_NOTEBOOK_RES_NEW \
     "insert into resources(parent_id, nodename, iscollection) values " \
     "(?, ?, 1) returning resource_id;"
 
+#define SQL_NOTEBOOK_NEW \
+    "insert into notebooks(resource_id) values " \
+    "(?) returning notebook_id;"
+
 static DBUConnection *connection;
 
 static UiThreadpool *queue;
@@ -796,16 +800,31 @@ typedef struct CreateNotebookJob {
 
 static int qthr_new_notebook(CreateNotebookJob *job) {
     DBUQuery *q = connection->createQuery(connection, NULL);
-    dbuQuerySetSQL(q, SQL_NOTEBOOK_NEW);
+    dbuQuerySetSQL(q, SQL_NOTEBOOK_RES_NEW);
     dbuQuerySetParamInt64(q, 1, job->resource->parent_id);
     dbuQuerySetParamString(q, 2, cx_str(job->resource->nodename));
     if(dbuQueryExec(q)) {
         job->error = 1;
     } else {
         DBUResult *result = dbuQueryGetResult(q);
-        int64_t new_resource_id;
         if(dbuResultAsInt64(result, &job->resource->resource_id)) {
             job->error = 2;
+        } else {
+            DBUQuery *q2 = connection->createQuery(connection, NULL);
+            dbuQuerySetSQL(q2, SQL_NOTEBOOK_NEW);
+            dbuQuerySetParamInt64(q2, 1, job->resource->resource_id);
+            if(dbuQueryExec(q2)) {
+                job->error = 3;
+            } else {
+                DBUResult *result2 = dbuQueryGetResult(q2);
+                int64_t notebook_id;
+                if(dbuResultAsInt64(result2, &notebook_id)) {
+                    job->error = 4;
+                } else {
+                    // TODO: create notebook object
+                }
+            }
+            dbuQueryFree(q2);
         }
     }
     dbuQueryFree(q);