]> uap-core.de Git - note.git/commitdiff
get note_id of newly inserted notes
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 6 May 2025 17:38:40 +0000 (19:38 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 6 May 2025 17:38:40 +0000 (19:38 +0200)
application/store.c

index 1400393d570f9ce02f22f18860482d6caf0ee258..9f20da88881b2b6ffebe320c82e9d0dabb53371e 100644 (file)
@@ -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, &note_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 {