diff options
| author | Carsten Dominik | 2010-12-11 17:42:53 +0100 |
|---|---|---|
| committer | Carsten Dominik | 2010-12-11 17:42:53 +0100 |
| commit | acedf35ce08b9df4a0dcbcd1413e7d85f1182034 (patch) | |
| tree | 240e26f10d2feb66e8c0cd0634082fcb7bd577e5 /lisp/org/ob-sql.el | |
| parent | 39321b94bfa4e50401e30caedfd09a06629f5bd2 (diff) | |
| download | emacs-acedf35ce08b9df4a0dcbcd1413e7d85f1182034.tar.gz emacs-acedf35ce08b9df4a0dcbcd1413e7d85f1182034.zip | |
Update to Org mode 7.4
Diffstat (limited to 'lisp/org/ob-sql.el')
| -rw-r--r-- | lisp/org/ob-sql.el | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/lisp/org/ob-sql.el b/lisp/org/ob-sql.el index 78e8a3b4377..5bb123d631b 100644 --- a/lisp/org/ob-sql.el +++ b/lisp/org/ob-sql.el | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | ;; Author: Eric Schulte | 5 | ;; Author: Eric Schulte |
| 6 | ;; Keywords: literate programming, reproducible research | 6 | ;; Keywords: literate programming, reproducible research |
| 7 | ;; Homepage: http://orgmode.org | 7 | ;; Homepage: http://orgmode.org |
| 8 | ;; Version: 7.3 | 8 | ;; Version: 7.4 |
| 9 | 9 | ||
| 10 | ;; This file is part of GNU Emacs. | 10 | ;; This file is part of GNU Emacs. |
| 11 | 11 | ||
| @@ -47,9 +47,15 @@ | |||
| 47 | (eval-when-compile (require 'cl)) | 47 | (eval-when-compile (require 'cl)) |
| 48 | 48 | ||
| 49 | (declare-function org-table-import "org-table" (file arg)) | 49 | (declare-function org-table-import "org-table" (file arg)) |
| 50 | (declare-function orgtbl-to-csv "org-table" (TABLE PARAMS)) | ||
| 50 | 51 | ||
| 51 | (defvar org-babel-default-header-args:sql '()) | 52 | (defvar org-babel-default-header-args:sql '()) |
| 52 | 53 | ||
| 54 | (defun org-babel-expand-body:sql (body params) | ||
| 55 | "Expand BODY according to the values of PARAMS." | ||
| 56 | (org-babel-sql-expand-vars | ||
| 57 | body (mapcar #'cdr (org-babel-get-header params :var)))) | ||
| 58 | |||
| 53 | (defun org-babel-execute:sql (body params) | 59 | (defun org-babel-execute:sql (body params) |
| 54 | "Execute a block of Sql code with Babel. | 60 | "Execute a block of Sql code with Babel. |
| 55 | This function is called by `org-babel-execute-src-block'." | 61 | This function is called by `org-babel-execute-src-block'." |
| @@ -60,6 +66,10 @@ This function is called by `org-babel-execute-src-block'." | |||
| 60 | (out-file (or (cdr (assoc :out-file params)) | 66 | (out-file (or (cdr (assoc :out-file params)) |
| 61 | (org-babel-temp-file "sql-out-"))) | 67 | (org-babel-temp-file "sql-out-"))) |
| 62 | (command (case (intern engine) | 68 | (command (case (intern engine) |
| 69 | ('msosql (format "osql %s -s \"\t\" -i %s -o %s" | ||
| 70 | (or cmdline "") | ||
| 71 | (org-babel-process-file-name in-file) | ||
| 72 | (org-babel-process-file-name out-file))) | ||
| 63 | ('mysql (format "mysql %s -e \"source %s\" > %s" | 73 | ('mysql (format "mysql %s -e \"source %s\" > %s" |
| 64 | (or cmdline "") | 74 | (or cmdline "") |
| 65 | (org-babel-process-file-name in-file) | 75 | (org-babel-process-file-name in-file) |
| @@ -70,11 +80,11 @@ This function is called by `org-babel-execute-src-block'." | |||
| 70 | (or cmdline ""))) | 80 | (or cmdline ""))) |
| 71 | (t (error "no support for the %s sql engine" engine))))) | 81 | (t (error "no support for the %s sql engine" engine))))) |
| 72 | (with-temp-file in-file | 82 | (with-temp-file in-file |
| 73 | (insert (org-babel-expand-body:generic body params))) | 83 | (insert (org-babel-expand-body:sql body params))) |
| 74 | (message command) | 84 | (message command) |
| 75 | (shell-command command) | 85 | (shell-command command) |
| 76 | (with-temp-buffer | 86 | (with-temp-buffer |
| 77 | (org-table-import out-file nil) | 87 | (org-table-import out-file '(16)) |
| 78 | (org-babel-reassemble-table | 88 | (org-babel-reassemble-table |
| 79 | (org-table-to-lisp) | 89 | (org-table-to-lisp) |
| 80 | (org-babel-pick-name (cdr (assoc :colname-names params)) | 90 | (org-babel-pick-name (cdr (assoc :colname-names params)) |
| @@ -82,6 +92,28 @@ This function is called by `org-babel-execute-src-block'." | |||
| 82 | (org-babel-pick-name (cdr (assoc :rowname-names params)) | 92 | (org-babel-pick-name (cdr (assoc :rowname-names params)) |
| 83 | (cdr (assoc :rownames params))))))) | 93 | (cdr (assoc :rownames params))))))) |
| 84 | 94 | ||
| 95 | (defun org-babel-sql-expand-vars (body vars) | ||
| 96 | "Expand the variables held in VARS in BODY." | ||
| 97 | (mapc | ||
| 98 | (lambda (pair) | ||
| 99 | (setq body | ||
| 100 | (replace-regexp-in-string | ||
| 101 | (format "\$%s" (car pair)) | ||
| 102 | ((lambda (val) | ||
| 103 | (if (listp val) | ||
| 104 | ((lambda (data-file) | ||
| 105 | (with-temp-file data-file | ||
| 106 | (insert (orgtbl-to-csv | ||
| 107 | val '(:fmt (lambda (el) (if (stringp el) | ||
| 108 | el | ||
| 109 | (format "%S" el))))))) | ||
| 110 | data-file) | ||
| 111 | (org-babel-temp-file "sql-data-")) | ||
| 112 | (if (stringp val) val (format "%S" val)))) | ||
| 113 | (cdr pair)) | ||
| 114 | body))) | ||
| 115 | vars) | ||
| 116 | body) | ||
| 85 | 117 | ||
| 86 | (defun org-babel-prep-session:sql (session params) | 118 | (defun org-babel-prep-session:sql (session params) |
| 87 | "Raise an error because Sql sessions aren't implemented." | 119 | "Raise an error because Sql sessions aren't implemented." |