kostafey / ejc-sql

Emacs SQL client uses Clojure JDBC.
278 stars 29 forks source link

ejc-eval-org-snippet should return org table if possible #180

Closed maxevtushok closed 1 year ago

maxevtushok commented 1 year ago

Currently If I eval code block in babel, it returns string, not org-table (list of lists), so it's not possible to use results of this block as an input in another block, like this:

#+name: dboutput
#+begin_src sql :results table
  select ('2023-08-14 06:32:00'::DateTime)::int * 1000 as a,
         ('2023-08-14 06:36:00'::DateTime)::int * 1000 as b
#+end_src
#+begin_src shell :var input=dboutput[2,0]
  echo ${input}
#+end_src

What I propose - is to try to return org-table if it is possible or string, if not (for working with error messages)

0001-ejc-eval-org-snippet-should-return-org-table-if-poss.patch

kostafey commented 1 year ago

@maxevtushok Thank you for this propose. Please create a pull request for it. I guess it can be simplified a little:

       (if ejc-org-mode-show-results
           (with-temp-buffer
             (insert-file-contents (ejc-get-result-file-path))
-            (buffer-string))))))
+            (or (org-babel-read-table)
+                (buffer-string)))))))

 (defun ejc-org-edit-special (orig-fun &rest args)
   (if (and (equal "sql" (car (org-babel-get-src-block-info)))