From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gary Oberbrunner Subject: SQL result as a single string, rather than table? Date: Thu, 28 Mar 2013 10:18:35 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8fb1ed068011e304d8fcd4f3 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:38291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ULDf4-00063e-EW for emacs-orgmode@gnu.org; Thu, 28 Mar 2013 10:18:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ULDf2-0002cL-8q for emacs-orgmode@gnu.org; Thu, 28 Mar 2013 10:18:38 -0400 Received: from mail-oa0-f45.google.com ([209.85.219.45]:58679) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ULDf2-0002cA-4O for emacs-orgmode@gnu.org; Thu, 28 Mar 2013 10:18:36 -0400 Received: by mail-oa0-f45.google.com with SMTP id o6so10104228oag.32 for ; Thu, 28 Mar 2013 07:18:35 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Orgmode Mailing List --e89a8fb1ed068011e304d8fcd4f3 Content-Type: text/plain; charset=ISO-8859-1 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 --e89a8fb1ed068011e304d8fcd4f3 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I'd like to be able to put a result from SQL inline in= to my exported document. =A0Something like this:

=
Latest database record is from src_sql[:colnames no :result= s 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 =3D...=3D), but at least on my Windows machin= e there is an extra ^M and newline in there. =A0I'd be happy to submit = a patch to strip whitespace from the end of the line in scalar mode, if peo= ple 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<= /div>
+++ b/lisp/ob-sql.el
@@ -138,7 +138,8 @@ This function is ca= lled by `org-babel-execute-src-block'."
=A0 =A0 =A0(org-= babel-eval command "")
=A0 =A0 =A0(org-babel-result-con= d result-params
=A0 =A0 =A0 =A0(with-temp-buffer
- =A0(progn (insert-file-contents-literally out-fil= e) (buffer-string)))
+= =A0(progn (insert-file-contents-literally out-file)
+ (replace-regexp-= in-string "[ \t\r\n]*$" "" (buffer-string))))
=A0 =A0 =A0 =A0(with-temp-buffer
=A0 (cond
=A0 =A0((or (eq (in= tern engine) 'mysql)

--
Gary --e89a8fb1ed068011e304d8fcd4f3--