]> uap-core.de Git - note.git/commitdiff
fix attachment bin_content update
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 8 Apr 2025 17:45:21 +0000 (19:45 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 8 Apr 2025 17:45:21 +0000 (19:45 +0200)
application/attachment.c
application/store.c

index 36a3b1bd30ca2c4bec3a1e65c4e3dc587b7a2157..a1b717b07125a71973525d26d4503f21bf026687 100644 (file)
@@ -61,6 +61,7 @@ void attachment_create_ui_model(UiContext *ctx, Attachment *attachment, Resource
         model->img = ui_generic_new(ctx, NULL);
     }
     model->ctx = ctx;
+    model->note_allocator = resource->model->note_allocator;
     
     model->parent_note = resource;
 }
@@ -91,15 +92,10 @@ void attachment_set_data(Attachment *attachment, cxmutstr data) {
  */
 void attachment_save(UiObject *obj, Attachment *attachment, bool cleanup_content) {
     if(!attachment->saved || !attachment->content_saved) {
-        cxmutstr content;
+        note_store_save_attachment_async(obj, attachment, NULL, NULL);
         if(cleanup_content) {
-            // bin_content can be moved to note_store_save_attachment_async
-            content = attachment->bin_content;
-            attachment->bin_content = (cxmutstr){NULL, 0};
-        } else {
-            content = attachment->bin_content.ptr ? cx_strdup(cx_strcast(attachment->bin_content)) : (cxmutstr){NULL, 0};
+            cxFree(attachment->ui->note_allocator, attachment->bin_content.ptr);
         }
-        note_store_save_attachment_async(obj, attachment, NULL, NULL);
     }
 }
 
index 0c1aff707ff7e99b75e296bd586a5eb84aba926b..99a5659514b8e74c5501f08deaa32554f3371b0d 100644 (file)
@@ -55,7 +55,7 @@
     "select * from cols\n" \
     "order by path;"
 
-#define SQL_NOTEBOOK_GET_NOTES "select resource_id, parent_id, name, title, lastmodified, creationdate, contenttype, created_by from resources where parent_id = ? ;"
+#define SQL_NOTEBOOK_GET_NOTES "select resource_id, parent_id, name, title, lastmodified, creationdate, contenttype, created_by from resources where parent_id = ? and bin_content is NULL;"
 
 #define SQL_NOTE_GET_CONTENT "select content, bin_content from resources where resource_id = ? ;"
 
@@ -620,6 +620,10 @@ typedef struct SaveAttachmentJob {
 
 static int qthr_save_attachment(SaveAttachmentJob *job) {
     if(job->attachment_id == 0) {
+        // create a new resource for the attachment data
+        // create an entry in the attachments table, which references
+        // the parent and attachment resource
+        
         DBUQuery *q = connection->createQuery(connection, NULL);
         dbuQuerySetSQL(q, SQL_ATTACHMENT_RESOURCE_NEW);
         dbuQuerySetParamInt64(q, 1, job->resource_id);