From 573b3d0fe12b35f6769e21c673cd39be3e1adcb0 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Tue, 8 Apr 2025 19:45:21 +0200 Subject: [PATCH] fix attachment bin_content update --- application/attachment.c | 10 +++------- application/store.c | 6 +++++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/application/attachment.c b/application/attachment.c index 36a3b1b..a1b717b 100644 --- a/application/attachment.c +++ b/application/attachment.c @@ -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); } } diff --git a/application/store.c b/application/store.c index 0c1aff7..99a5659 100644 --- a/application/store.c +++ b/application/store.c @@ -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); -- 2.43.5