emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Gary Oberbrunner <garyo@oberbrunner.com>
To: Orgmode Mailing List <emacs-orgmode@gnu.org>
Subject: SQL result as a single string, rather than table?
Date: Thu, 28 Mar 2013 10:18:35 -0400	[thread overview]
Message-ID: <CAFChFyjUg3uiuZCKQM2SHPABSQKZjnKy2h7WTQ7mindar7_Vnw@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1123 bytes --]

I'd like to be able to put a result from SQL inline into my exported
document.  Something like this:

Latest database record is from src_sql[:colnames no :results scalar]{select
DATE(CreatedAt) from Event order by CreatedAt desc limit 1;}.

In that case, the SQL result almost works (it surrounds the results with
=...=), but at least on my Windows machine there is an extra ^M and newline
in there.  I'd be happy to submit a patch to strip whitespace from the end
of the line in scalar mode, if people think that's a good idea.

In fact here's what I propose:

diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 658a54f..ac999f4 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -138,7 +138,8 @@ This function is called by
`org-babel-execute-src-block'."
     (org-babel-eval command "")
     (org-babel-result-cond result-params
       (with-temp-buffer
-  (progn (insert-file-contents-literally out-file) (buffer-string)))
+  (progn (insert-file-contents-literally out-file)
+ (replace-regexp-in-string "[ \t\r\n]*$" "" (buffer-string))))
       (with-temp-buffer
  (cond
   ((or (eq (intern engine) 'mysql)

-- 
Gary

[-- Attachment #2: Type: text/html, Size: 1763 bytes --]

                 reply	other threads:[~2013-03-28 14:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFChFyjUg3uiuZCKQM2SHPABSQKZjnKy2h7WTQ7mindar7_Vnw@mail.gmail.com \
    --to=garyo@oberbrunner.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).