diff options
Diffstat (limited to 'lisp/org/ob-sql.el')
-rw-r--r-- | lisp/org/ob-sql.el | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/lisp/org/ob-sql.el b/lisp/org/ob-sql.el index 7a5c7c8a46a..8e92635bc1f 100644 --- a/lisp/org/ob-sql.el +++ b/lisp/org/ob-sql.el @@ -5,7 +5,6 @@ ;; Author: Eric Schulte ;; Keywords: literate programming, reproducible research ;; Homepage: http://orgmode.org -;; Version: 7.7 ;; This file is part of GNU Emacs. @@ -32,7 +31,7 @@ ;; ;; Also SQL evaluation generally takes place inside of a database. ;; -;; For now let's just allow a generic ':cmdline' header argument. +;; For now lets just allow a generic ':cmdline' header argument. ;; ;; TODO: ;; @@ -40,7 +39,7 @@ ;; - add more useful header arguments (user, passwd, database, etc...) ;; - support for more engines (currently only supports mysql) ;; - what's a reasonable way to drop table data into SQL? -;; +;; ;;; Code: (require 'ob) @@ -51,6 +50,9 @@ (defvar org-babel-default-header-args:sql '()) +(defvar org-babel-header-arg-names:sql + '(engine out-file)) + (defun org-babel-expand-body:sql (body params) "Expand BODY according to the values of PARAMS." (org-babel-sql-expand-vars @@ -85,31 +87,38 @@ This function is called by `org-babel-execute-src-block'." (insert (org-babel-expand-body:sql body params))) (message command) (shell-command command) - (with-temp-buffer - ;; need to figure out what the delimiter is for the header row + (if (or (member "scalar" result-params) + (member "verbatim" result-params) + (member "html" result-params) + (member "code" result-params) + (equal (point-min) (point-max))) + (with-temp-buffer + (progn (insert-file-contents-literally out-file) (buffer-string))) (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 - (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)) - (cdr (assoc :rownames params))))))) + ;; 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 + (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)) + (cdr (assoc :rownames params)))))))) (defun org-babel-sql-expand-vars (body vars) "Expand the variables held in VARS in BODY." |