added note to logbook data in org sql db

This commit is contained in:
ndwarshuis 2018-12-25 02:23:40 -05:00
parent f78b3882ce
commit c602ad7081
1 changed files with 42 additions and 39 deletions

View File

@ -2865,7 +2865,7 @@ If RIGHT is t, get the right half instead of the left."
(if (equal 'line-break (org-element-type cur)) (if (equal 'line-break (org-element-type cur))
(if right rem acc) (if right rem acc)
(funcall scan rem (append acc (list cur))))) (funcall scan rem (append acc (list cur)))))
acc)))) (unless right acc)))))
(funcall scan contents))) (funcall scan contents)))
#+END_SRC #+END_SRC
**** org sql constants and variables **** org sql constants and variables
@ -3098,6 +3098,8 @@ ARCHIVE-FILE-PATH is the path to the archive file."
;; split entry into right / left components via linebreak ;; split entry into right / left components via linebreak
(left (nd/org-element-split-linebreak contents)) (left (nd/org-element-split-linebreak contents))
(right (nd/org-element-split-linebreak contents t)) (right (nd/org-element-split-linebreak contents t))
(note (string-trim (substring-no-properties
(org-element-interpret-data right))))
(entry-str (string-trim (substring-no-properties (entry-str (string-trim (substring-no-properties
(org-element-interpret-data left)))) (org-element-interpret-data left))))
(note-parsed (nd/org-logbook-match-entry entry-str)) (note-parsed (nd/org-logbook-match-entry entry-str))
@ -3106,14 +3108,15 @@ ARCHIVE-FILE-PATH is the path to the archive file."
time-index time-logged logbook-data) time-index time-logged logbook-data)
;; get time recorded based on note type ;; get time recorded based on note type
(set-match-data note-match) (when note-type
(setq time-index (set-match-data note-match)
(cond (setq time-index
((memq note-type '(done note refile)) 1) (cond
((memq note-type '(reschedule delschedule redeadline deldeadline)) 3) ((memq note-type '(done note refile)) 1)
((eq note-type 'state) 5) ((memq note-type '(reschedule delschedule redeadline deldeadline)) 3)
(t (error (concat "Unknown type: " (symbol-name note-type)))))) ((eq note-type 'state) 5)
(setq time-logged (match-string time-index entry-str)) (t (error (concat "Unknown type: " (symbol-name note-type))))))
(setq time-logged (match-string time-index entry-str)))
;; insert into general logbook table first ;; insert into general logbook table first
(nd/sql-insert nd/org-sqlite-db-path (nd/sql-insert nd/org-sqlite-db-path
@ -3122,43 +3125,43 @@ ARCHIVE-FILE-PATH is the path to the archive file."
headline-file-offset headline-file-offset
entry-file-offset entry-file-offset
time-logged time-logged
;; TODO add contents note))
nil))
;; insert into auxiliary logging tables ;; insert into auxiliary logging tables
(cond (when note-type
((eq note-type 'state) (cond
(let* ((state-old (or (match-string 3 entry-str) ((eq note-type 'state)
(match-string 4 entry-str))) (let* ((state-old (or (match-string 3 entry-str)
(state-new (or (match-string 1 entry-str) (match-string 4 entry-str)))
(match-string 2 entry-str)))) (state-new (or (match-string 1 entry-str)
(nd/sql-insert nd/org-sqlite-db-path (match-string 2 entry-str))))
"state_changes" (nd/sql-insert nd/org-sqlite-db-path
(list archive-file-path "state_changes"
entry-file-offset (list archive-file-path
state-old entry-file-offset
state-new)))) state-old
state-new))))
((memq note-type '(reschedule delschedule redeadline deldeadline)) ((memq note-type '(reschedule delschedule redeadline deldeadline))
(let* ((time-old (match-string 1 entry-str)) (let* ((time-old (match-string 1 entry-str))
(schedule (memq note-type '(reschedule delschedule))) (schedule (memq note-type '(reschedule delschedule)))
(time-new (nd/org-element-timestamp-raw (time-new (nd/org-element-timestamp-raw
(if schedule :scheduled :deadline) (if schedule :scheduled :deadline)
parent-headline)) parent-headline))
(planning-type (if schedule "s" "d"))) (planning-type (if schedule "s" "d")))
(nd/sql-insert nd/org-sqlite-db-path (nd/sql-insert nd/org-sqlite-db-path
"planning_changes" "planning_changes"
(list archive-file-path (list archive-file-path
entry-file-offset entry-file-offset
time-old time-old
time-new time-new
planning-type)))) planning-type))))
;; no action required for these ;; no action required for these
((memq note-type '(done refile note)) (ignore)) ((memq note-type '(done refile note)) (ignore))
;; this shouldn't happen ;; this shouldn't happen
(t (error (concat "Unknown entry type: " (symbol-name note-type))))))))) (t (error (concat "Unknown entry type: " (symbol-name note-type))))))))))
(defun nd/org-archive-to-db () (defun nd/org-archive-to-db ()
"Transfer archive files to sqlite database." "Transfer archive files to sqlite database."