]> uap-core.de Git - note.git/commitdiff
new notes are also added to the notes table the notes list only contains resources... main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 2 May 2025 17:29:13 +0000 (19:29 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 2 May 2025 17:29:13 +0000 (19:29 +0200)
application/store.c
application/store_sqlite.c

index ad88c97eb6cdcbfce13538455560c8f3d10436e5..6b92ff68d6deb429f52a9ee048683c428960da45 100644 (file)
     "select * from cols\n" \
     "order by path;"
 
-#define SQL_NOTEBOOK_GET_NOTES "select resource_id, parent_id, nodename, displayname, lastmodified, creationdate, iscollection, contenttype from resources where parent_id = ? ;"
+#define SQL_NOTEBOOK_GET_NOTES "select r.resource_id, r.parent_id, r.nodename, r.displayname, r.lastmodified, r.creationdate, r.iscollection, r.contenttype from resources r inner join notes n on r.resource_id = n.resource_id where parent_id = ? ;"
 
 #define SQL_NOTE_GET_CONTENT "select content from resources where resource_id = ? ;"
 
-#define SQL_NOTE_NEW "insert into resources(parent_id, nodename, displayname, lastmodified, creationdate, content) values (?, ?, ?, unixepoch(), unixepoch(), ?) returning resource_id;"
+#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_SAVE "update resources set nodename = ? ," \
     "displayname = ? ," \
@@ -501,7 +503,7 @@ static void uithr_save_note_finished(UiEvent *event, SaveNoteJob *job) {
 static int qthr_new_note(SaveNoteJob *job) {
     Resource *n = job->note;
     DBUQuery *q = connection->createQuery(connection, NULL);
-    dbuQuerySetSQL(q, SQL_NOTE_NEW);
+    dbuQuerySetSQL(q, SQL_NOTE_RESOURCE_NEW);
     dbuQuerySetParamInt64(q, 1, n->parent_id);
     dbuQuerySetParamString(q, 2, cx_str(n->displayname));
     dbuQuerySetParamString(q, 3, cx_str(n->displayname));
@@ -516,6 +518,15 @@ static int qthr_new_note(SaveNoteJob *job) {
                 long long new_id = 0;
                 cx_strtoll(new_id_str, &new_id, 10);
                 n->resource_id = new_id;
+                
+                DBUQuery *q2 = connection->createQuery(connection, NULL);
+                dbuQuerySetSQL(q2, SQL_NOTE_NEW);
+                dbuQuerySetParamInt64(q2, 1, new_id);
+                dbuQuerySetParamInt64(q2, 2, 0);
+                if(dbuQueryExec(q2)) {
+                    job->error = 3;
+                }
+                dbuQueryFree(q2);
             }
         } else {
             job->error = 2;
index 396fa39287e51d73f1bbd8cf1d870dd6d29d1542..fc2cc0db3c2539dbcf7d3acb1b2ab9da7db9887c 100644 (file)
     "foreign key (parent_id) references resources(resource_id), " \
     "unique (parent_id, nodename) " \
     ");"
+#define SQL_CREATE_TABLE_NOTES "create table notes( " \
+    "note_id                 integer primary key, " \
+    "resource_id             integer, " \
+    "type                    integer, " \
+    "status                  text, " \
+    "targetdate              integer, " \
+    "foreign key (resource_id) references resources(resource_id) " \
+    ");"
 #define SQL_CREATE_TABLE_ATTACHMENTS "create table attachments( " \
     "attachment_id           integer primary key, " \
     "attachment_resource_id  integer, " \
@@ -85,6 +93,7 @@ int store_sqlite_init_db(DBUConnection *connection) {
         SQL_CREATE_TABLE_REPOSITORIES,
         SQL_CREATE_TABLE_USER_SETTINGS,
         SQL_CREATE_TABLE_RESOURCES,
+        SQL_CREATE_TABLE_NOTES,
         SQL_CREATE_TABLE_ATTACHMENTS
     };
     int nsql = sizeof(sql) / sizeof(char*);