model->img = ui_generic_new(ctx, NULL);
}
model->ctx = ctx;
+ model->note_allocator = resource->model->note_allocator;
model->parent_note = resource;
}
*/
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);
}
}
"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 = ? ;"
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);