summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Sebold <csebold@gmail.com>2010-12-21 10:33:37 -0700
committerEric Schulte <schulte.eric@gmail.com>2010-12-21 10:33:37 -0700
commit9c4b936c0e91b2226b8d650124e9cfc90f4c301f (patch)
tree32f048eb69768fdcb1a159c8e05f15e201796705
parentece347e32c571967c1c2f3f523ca7444d185a2ac (diff)
downloadorg-mode-9c4b936c0e91b2226b8d650124e9cfc90f4c301f.tar.gz
ob-sql: header line in results table
-rw-r--r--lisp/ob-sql.el23
1 files changed, 21 insertions, 2 deletions
diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 5bb123d..364070e 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 "")
@@ -74,7 +75,8 @@ This function is called by `org-babel-execute-src-block'."
(or cmdline "")
(org-babel-process-file-name in-file)
(org-babel-process-file-name out-file)))
- ('postgresql (format "psql -A -P footer=off -F \"\t\" -f %s -o %s %s"
+ ('postgresql (format
+ "psql -A -P footer=off -F \"\t\" -f %s -o %s %s"
(org-babel-process-file-name in-file)
(org-babel-process-file-name out-file)
(or cmdline "")))
@@ -84,9 +86,26 @@ 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)))
+ (goto-char (point-max))
+ (forward-char -1)
+ (while (looking-at "\n")
+ (delete-char 1)
+ (goto-char (point-max))
+ (forward-char -1))
+ (write-file out-file))
(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))