org-babel-sql.el 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ;;; org-babel-sql.el --- org-babel functions for sql evaluation
  2. ;; Copyright (C) 2009 Eric Schulte
  3. ;; Author: Eric Schulte
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 0.01
  7. ;;; License:
  8. ;; This program is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 3, or (at your option)
  11. ;; any later version.
  12. ;;
  13. ;; This program is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;;
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;; Commentary:
  23. ;; Org-Babel support for evaluating sql source code.
  24. ;;
  25. ;; SQL is somewhat unique in that there are many different engines for
  26. ;; the evaluation of sql (Mysql, PostgreSQL, etc...), so much of this
  27. ;; file will have to be implemented engine by engine.
  28. ;;
  29. ;; Also SQL evaluation generally takes place inside of a database.
  30. ;;; Code:
  31. (require 'org-babel)
  32. (org-babel-add-interpreter "sql")
  33. (add-to-list 'org-babel-tangle-langs '("sql" "sql"))
  34. (defun org-babel-execute:sql (body params)
  35. "Execute a block of Sql code with org-babel. This function is
  36. called by `org-babel-execute-src-block' via multiple-value-bind."
  37. (message "executing Sql source code block")
  38. )
  39. (defun org-babel-prep-session:sql (session params)
  40. "Prepare SESSION according to the header arguments specified in PARAMS."
  41. ;; (message "params=%S" params) ;; debugging
  42. )
  43. ;; helper functions
  44. (defun org-babel-sql-var-to-sql (var)
  45. "Convert an elisp var into a string of sql source code
  46. specifying a var of the same value."
  47. (if (listp var)
  48. (concat "[" (mapconcat #'org-babel-sql-var-to-sql var ", ") "]")
  49. (format "%S" var)))
  50. (defun org-babel-sql-table-or-string (results)
  51. "If the results look like a table, then convert them into an
  52. Emacs-lisp table, otherwise return the results as a string."
  53. )
  54. (provide 'org-babel-sql)
  55. ;;; org-babel-sql.el ends here