Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] a debugging tip with Empty SQL vector expression #1534

Closed
randomwangran opened this issue May 28, 2021 · 2 comments
Closed

[v2] a debugging tip with Empty SQL vector expression #1534

randomwangran opened this issue May 28, 2021 · 2 comments

Comments

@randomwangran
Copy link

randomwangran commented May 28, 2021

Just want to share my experience with V2 migration b183fd4.

If the file-level info is like this:

:PROPERTIES:
:ID:       15be2774-f063-40a3-a489-ab7e65ab54d9
:ROAM_ALIASES:
:END:
#+TITLE: C\+\+

Emacs will through an error, which is very hard to detect the cause.

emacsql-error: Invalid SQL statement: "Empty SQL vector expression."

:ROAM_ALIASES: is automatically generated by this script which was written by @jethrokuan with inputs from @d12frosted

Just make sure :ROAM_ALIASES: has something.

I spent a lot of time finding the root cause. I hope someone else can save a little bit of time just in case.

@d12frosted
Copy link
Contributor

🤔 this script should not cause such problem because vulpea-buffer-prop-get and vulpea-buffer-prop-get-list return nil on empty values/strings. Though I am really curious, what was the original note that become malformed during migration process.

;; if roam_key is present but is empty, ROAM_REFS will not be create
(when-let* ((ref (vulpea-buffer-prop-get "roam_key")))
    (org-set-property "ROAM_REFS" ref)
    (let ((case-fold-search t))
      (org-with-point-at 1
        (while (re-search-forward "^#\\+roam_key:" (point-max) t)
          (beginning-of-line)
          (kill-line 1)))))

Usage example:

:PROPERTIES:
:ID:       15be2774-f063-40a3-a489-ab7e65ab54d9
:END:
#+TITLE: C\+\+
#+ROAM_ALIAS:
> (vulpea-buffer-prop-get "roam_alias")
nil

> (vulpea-buffer-prop-get-list "roam_alias")
nil

While I was writing this message, I realised that vulpea-buffer-prop-get still may cause a problem when you have an empty string of non-zero length (e.g. multiple trailing spaces). Fixed that in d12frosted/vulpea@f65671a

@randomwangran
Copy link
Author

Hi @d12frosted :

Sorry for the delaying this response. V2 is so good that I enjoy it too much.

The migration was not smooth probably because I have some personal hooks in Org-mode. I remembered that I executed and killed the migration script a couple of times before the database was built. The root cause might be very hard to detect.

The migration script is good. I test it with the problematic file again. The :ROAM_ALIASES is successfully added to the :PROPERTIES: drawer.

(defun org-roam-v1-to-v2 ()
  ;; Create file level ID
  (org-with-point-at 1
    (org-id-get-create))
  ;; Replace roam_key into properties drawer roam_ref
  (when-let* ((refs (mapcan #'split-string-and-unquote
                            (cdar (org-collect-keywords '("roam_key"))))))
    (let ((case-fold-search t))
      (org-with-point-at 1
        (org-set-property "ROAM_REFS" (combine-and-quote-strings refs))
        (while (re-search-forward "^#\\+roam_key:" (point-max) t)
          (kill-line 1)))))

  ;; Replace roam_alias into properties drawer roam_aliases
  (when-let* ((aliases (mapcan #'split-string-and-unquote
                               (cdar (org-collect-keywords '("roam_alias"))))))
    (let ((case-fold-search t))
      (org-with-point-at 1
        (org-set-property "ROAM_ALIASES" (combine-and-quote-strings aliases))
        (while (re-search-forward "^#\\+roam_alias:" (point-max) t)
          (kill-line 1)))))

  ;; Replace #+roam_tags into #+filetags
  (org-with-point-at 1
    (let ((case-fold-search t))
      (while (search-forward "#+filetags:" nil t)
        (replace-match "#+filetags:" nil t))))
  (save-buffer))

P.s.: I also enjoy your blog about dynamic agendas. It is really cool!

Thanks for your contribution @d12frosted and the community. I really appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants