From: Olaf Wintermann Date: Wed, 21 May 2025 19:49:08 +0000 (+0200) Subject: also insert row into notebooks table when creating a new notebook X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=57d08758755c1a9d11cb58c6a108d1c8ee1f2f95;p=note.git also insert row into notebooks table when creating a new notebook --- diff --git a/application/store.c b/application/store.c index 7a27179..21c62f3 100644 --- a/application/store.c +++ b/application/store.c @@ -93,10 +93,14 @@ "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, ¬ebook_id)) { + job->error = 4; + } else { + // TODO: create notebook object + } + } + dbuQueryFree(q2); } } dbuQueryFree(q);