I am trying to query the database from within a function using variables.
In my tests, I tried gathering all files which have a property named “TYPE” set to the value “how to”.
I could not find exhaustive documentation about org-roam-db-query, and I usually use the org-roam-ql to do queries. But I was getting errors too using variables, so I figured I should remove the middle man to try and solve that problem.
Thanks to a few examples here and there, I can retrieve a list of 40 files using the code below:
I will spare you all my other attempts, the best I could do was writing the follwing function which returns 0 instead of 40, but has at least the merit of not throwing a stringp type error:
I would really appreciate some help because I do have a few functions depending on that kind of logic, and I am really stuck (and I have not even started trying to query using tags!).
so the key seems to be to properly escape the % and " in the string.
It appers that you need a string st such that (format st) will return the string (without single quotes) that SQL expects.
#+begin_src emacs-lisp :exports both
(format "select properties
from nodes
where properties LIKE '%%\"CATEGORY\" . \"faq_git\"%%'
")
#+end_src
#+RESULTS:
#+begin_example
select properties
from nodes
where properties LIKE '%"CATEGORY" . "faq_git"%'
#+end_example
This also seems to work (using quote, only quoting ")
Thanks, I did actually, and, backquotes easily solved the problem with org-roam-ql. When using org-roam-db-query I tend to go for the (format "%s" sql-string) solution from @dmg answer.
As far as I know, the emacsql package doesn’t have that functionality. My understanding is it requires a pointer to a routine sqlite can call, and I am not sure how to even go about that. You may want to ask the authors there to see if it possible.