emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Charles Sebold <csebold@gmail.com>
To: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Patch for ob-sql.el SQL output
Date: Tue, 21 Dec 2010 09:02:45 -0600	[thread overview]
Message-ID: <AANLkTinC3ep05g6nbGpcPs4uRTps=hv3DOn7X8cpDtYS@mail.gmail.com> (raw)

I use org-mode and babel under Windows with osql, and the line
separating the header from the rest of the rows in the output was
bothering me.

I don't know that this is a really good fix, but maybe it's a start
for one?  I've filled out paperwork with FSF for copyright assignment.
 It looks for the first output line of all dashes and replaces it
later with the 'hline when the table is lisp-ified.  I didn't test
this with mysql or postgresql.

diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 5bb123d..13e9bd3 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -65,6 +65,7 @@ This function is called by `org-babel-execute-src-block'."
          (in-file (org-babel-temp-file "sql-in-"))
          (out-file (or (cdr (assoc :out-file params))
                        (org-babel-temp-file "sql-out-")))
+         (header-delim "")
          (command (case (intern engine)
                     ('msosql (format "osql %s -s \"\t\" -i %s -o %s"
                                      (or cmdline "")
@@ -84,9 +85,19 @@ This function is called by `org-babel-execute-src-block'."
     (message command)
     (shell-command command)
     (with-temp-buffer
+      ; need to figure out what the delimiter is for the header row
+      (with-temp-buffer
+        (insert-file-contents out-file)
+        (goto-char (point-min))
+        (when (re-search-forward "^\\(-+\\)$" nil t)
+          (setq header-delim (match-string-no-properties 1))))
       (org-table-import out-file '(16))
       (org-babel-reassemble-table
-       (org-table-to-lisp)
+       (mapcar (lambda (x)
+                 (if (string= (car x) header-delim)
+                     'hline
+                   x))
+               (org-table-to-lisp))
        (org-babel-pick-name (cdr (assoc :colname-names params))
                            (cdr (assoc :colnames params)))
        (org-babel-pick-name (cdr (assoc :rowname-names params))
--
Charles Sebold
Ego delendus sum

             reply	other threads:[~2010-12-21 15:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-21 15:02 Charles Sebold [this message]
2010-12-21 15:34 ` Patch for ob-sql.el SQL output Sébastien Vauban
2010-12-21 16:57   ` Charles Sebold
2010-12-21 17:08     ` Charles Sebold
2010-12-21 17:34       ` Eric Schulte
2010-12-21 18:58         ` Charles Sebold
2010-12-22 10:23           ` Sébastien Vauban
2010-12-22 10:05         ` Sébastien Vauban

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='AANLkTinC3ep05g6nbGpcPs4uRTps=hv3DOn7X8cpDtYS@mail.gmail.com' \
    --to=csebold@gmail.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).