From a2da2e3b2eb745795f32cb9381668f8741746ae5 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Tue, 6 May 2025 19:38:40 +0200 Subject: [PATCH] get note_id of newly inserted notes --- application/store.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/application/store.c b/application/store.c index 1400393..9f20da8 100644 --- a/application/store.c +++ b/application/store.c @@ -62,7 +62,7 @@ #define SQL_NOTE_RESOURCE_NEW "insert into resources(parent_id, nodename, displayname, lastmodified, creationdate, content) values (?, ?, ?, unixepoch(), unixepoch(), ?) returning resource_id;" -#define SQL_NOTE_NEW "insert into notes(resource_id, type) values (?, ?);" +#define SQL_NOTE_NEW "insert into notes(resource_id, type) values (?, ?) returning note_id;" #define SQL_NOTE_SAVE "update resources set nodename = ? ," \ "displayname = ? ," \ @@ -523,9 +523,17 @@ static int qthr_new_note(SaveNoteJob *job) { dbuQuerySetSQL(q2, SQL_NOTE_NEW); dbuQuerySetParamInt64(q2, 1, new_id); dbuQuerySetParamInt64(q2, 2, 0); - if(dbuQueryExec(q2)) { + if(!dbuQueryExec(q2)) { + DBUResult *insert2Result = dbuQueryGetResult(q); + int64_t note_id; + if(dbuResultAsInt64(insert2Result, ¬e_id)) { + job->note->note_id = note_id; + } else { + job->error = 4; + } + } else { job->error = 3; - } // TODO: save note_id in the Note object + } dbuQueryFree(q2); } } else { -- 2.43.5