* SQL result as a single string, rather than table?
@ 2013-03-28 14:18 Gary Oberbrunner
0 siblings, 0 replies; only message in thread
From: Gary Oberbrunner @ 2013-03-28 14:18 UTC (permalink / raw)
To: Orgmode Mailing List
[-- 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 --]
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2013-03-28 14:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-28 14:18 SQL result as a single string, rather than table? Gary Oberbrunner
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).