;;; ob-sqlite.el --- org-babel functions for sqlite database interaction
-;; Copyright (C) 2010 Free Software Foundation, Inc.
+;; Copyright (C) 2010-2012 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
-;; Version: 7.3
;; This file is part of GNU Emacs.
;;; Code:
(require 'ob)
+(require 'ob-eval)
(require 'ob-ref)
(declare-function org-fill-template "org" (template alist))
"Execute a block of Sqlite code with Babel.
This function is called by `org-babel-execute-src-block'."
(let ((result-params (split-string (or (cdr (assoc :results params)) "")))
- (vars (org-babel-get-header params :var))
(db (cdr (assoc :db params)))
(separator (cdr (assoc :separator params)))
(nullvalue (cdr (assoc :nullvalue params)))
(unless db (error "ob-sqlite: can't evaluate without a database."))
(with-temp-buffer
(insert
- (shell-command-to-string
+ (org-babel-eval
(org-fill-template
- "%cmd -init %body %header %separator %nullvalue %others %csv %db "
+ "%cmd %header %separator %nullvalue %others %csv %db "
(list
- (cons "body" ((lambda (sql-file)
- (with-temp-file sql-file
- (insert (org-babel-expand-body:sqlite body params)))
- sql-file)
- (org-babel-temp-file "sqlite-sql-")))
(cons "cmd" org-babel-sqlite3-command)
(cons "header" (if headers-p "-header" "-noheader"))
(cons "separator"
(member :html others) separator)
""
"-csv"))
- (cons "db " db)))))
+ (cons "db " db)))
+ ;; body of the code block
+ (org-babel-expand-body:sqlite body params)))
(if (or (member "scalar" result-params)
+ (member "verbatim" result-params)
(member "html" result-params)
(member "code" result-params)
(equal (point-min) (point-max)))
(buffer-string)
- (org-table-convert-region (point-min) (point-max))
+ (org-table-convert-region (point-min) (point-max)
+ (if (or (member :csv others)
+ (member :column others)
+ (member :line others)
+ (member :list others)
+ (member :html others) separator)
+ nil
+ '(4)))
(org-babel-sqlite-table-or-scalar
(org-babel-sqlite-offset-colnames
(org-table-to-lisp) headers-p))))))
(provide 'ob-sqlite)
-;; arch-tag: 5c03d7f2-0f72-48b8-bbd1-35aafea248ac
+
;;; ob-sqlite.el ends here