forked from mirrors/org-mode
ob-sql: Add sqsh engine
* lisp/ob-sql.el (org-babel-sql-dbstring-sqsh): New function. (org-babel-execute:sql): Add `sqsh' engine.
This commit is contained in:
parent
b25dd07bc0
commit
0063075f65
17
etc/ORG-NEWS
17
etc/ORG-NEWS
|
@ -33,7 +33,6 @@ into
|
||||||
Creation of a new setting to specify the Cider timeout. By setting
|
Creation of a new setting to specify the Cider timeout. By setting
|
||||||
the =org-babel-clojure-sync-nrepl-timeout= setting option. The value
|
the =org-babel-clojure-sync-nrepl-timeout= setting option. The value
|
||||||
is in seconds and if set to =nil= then no timeout will occur.
|
is in seconds and if set to =nil= then no timeout will occur.
|
||||||
|
|
||||||
**** Clojure: new header ~:show-process~
|
**** Clojure: new header ~:show-process~
|
||||||
|
|
||||||
A new block code header has been created for Org Babel that enables
|
A new block code header has been created for Org Babel that enables
|
||||||
|
@ -67,6 +66,22 @@ is specified then all the output from the window will appears in the
|
||||||
results section. If =value= is specified, then only the last returned
|
results section. If =value= is specified, then only the last returned
|
||||||
value of the code will be displayed in the results section.
|
value of the code will be displayed in the results section.
|
||||||
|
|
||||||
|
**** SQL: new engine added ~sqsh~
|
||||||
|
|
||||||
|
A new engine was added to support ~sqsh~ command line utility for use
|
||||||
|
against Microsoft SQL Server or Sybase SQL server.
|
||||||
|
|
||||||
|
More information on ~sqsh~ can be found here: [[https://sourceforge.net/projects/sqsh/][sourceforge/sqsh]]
|
||||||
|
|
||||||
|
To use ~sqsh~ in an *sql* =SRC_BLK= set the =:engine= like this:
|
||||||
|
|
||||||
|
#+begin_example
|
||||||
|
,#+BEGIN_SRC sql :engine sqsh :dbhost my_host :dbuser master :dbpassword pass :database support
|
||||||
|
Select * From Users
|
||||||
|
Where clue > 0
|
||||||
|
,#+END_SRC
|
||||||
|
#+end_example
|
||||||
|
|
||||||
*** Horizontal rules are no longer ignored in LaTeX table math mode
|
*** Horizontal rules are no longer ignored in LaTeX table math mode
|
||||||
|
|
||||||
** Removed options
|
** Removed options
|
||||||
|
|
|
@ -43,15 +43,24 @@
|
||||||
;; - colnames (default, nil, means "yes")
|
;; - colnames (default, nil, means "yes")
|
||||||
;; - result-params
|
;; - result-params
|
||||||
;; - out-file
|
;; - out-file
|
||||||
|
;;
|
||||||
;; The following are used but not really implemented for SQL:
|
;; The following are used but not really implemented for SQL:
|
||||||
;; - colname-names
|
;; - colname-names
|
||||||
;; - rownames
|
;; - rownames
|
||||||
;; - rowname-names
|
;; - rowname-names
|
||||||
;;
|
;;
|
||||||
|
;; Engines supported:
|
||||||
|
;; - mysql
|
||||||
|
;; - dbi
|
||||||
|
;; - mssql
|
||||||
|
;; - sqsh
|
||||||
|
;; - postgresql
|
||||||
|
;; - oracle
|
||||||
|
;;
|
||||||
;; TODO:
|
;; TODO:
|
||||||
;;
|
;;
|
||||||
;; - support for sessions
|
;; - support for sessions
|
||||||
;; - support for more engines (currently only supports mysql)
|
;; - support for more engines
|
||||||
;; - what's a reasonable way to drop table data into SQL?
|
;; - what's a reasonable way to drop table data into SQL?
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
@ -116,6 +125,18 @@ SQL Server on Windows and Linux platform."
|
||||||
(when database (format "-d \"%s\"" database))))
|
(when database (format "-d \"%s\"" database))))
|
||||||
" "))
|
" "))
|
||||||
|
|
||||||
|
(defun org-babel-sql-dbstring-sqsh (host user password database)
|
||||||
|
"Make sqsh commmand line args for database connection.
|
||||||
|
\"sqsh\" is one method to access Sybase or MS SQL via Linux platform"
|
||||||
|
(mapconcat #'identity
|
||||||
|
(delq nil
|
||||||
|
(list (when host (format "-S \"%s\"" host))
|
||||||
|
(when user (format "-U \"%s\"" user))
|
||||||
|
(when password (format "-P \"%s\"" password))
|
||||||
|
(when database (format "-D \"%s\"" database))))
|
||||||
|
" "))
|
||||||
|
|
||||||
|
|
||||||
(defun org-babel-sql-convert-standard-filename (file)
|
(defun org-babel-sql-convert-standard-filename (file)
|
||||||
"Convert the file name to OS standard.
|
"Convert the file name to OS standard.
|
||||||
If in Cygwin environment, uses Cygwin specific function to
|
If in Cygwin environment, uses Cygwin specific function to
|
||||||
|
@ -179,6 +200,14 @@ footer=off -F \"\t\" %s -f %s -o %s %s"
|
||||||
(org-babel-process-file-name in-file)
|
(org-babel-process-file-name in-file)
|
||||||
(org-babel-process-file-name out-file)
|
(org-babel-process-file-name out-file)
|
||||||
(or cmdline "")))
|
(or cmdline "")))
|
||||||
|
(`sqsh (format "sqsh %s %s -i %s -o %s -m csv"
|
||||||
|
(or cmdline "")
|
||||||
|
(org-babel-sql-dbstring-sqsh
|
||||||
|
dbhost dbuser dbpassword database)
|
||||||
|
(org-babel-sql-convert-standard-filename
|
||||||
|
(org-babel-process-file-name in-file))
|
||||||
|
(org-babel-sql-convert-standard-filename
|
||||||
|
(org-babel-process-file-name out-file))))
|
||||||
(`oracle (format
|
(`oracle (format
|
||||||
"sqlplus -s %s < %s > %s"
|
"sqlplus -s %s < %s > %s"
|
||||||
(org-babel-sql-dbstring-oracle
|
(org-babel-sql-dbstring-oracle
|
||||||
|
@ -203,18 +232,20 @@ SET MARKUP HTML OFF SPOOL OFF
|
||||||
SET COLSEP '|'
|
SET COLSEP '|'
|
||||||
|
|
||||||
")
|
")
|
||||||
(`mssql "SET NOCOUNT ON
|
((or `mssql `sqsh) "SET NOCOUNT ON
|
||||||
|
|
||||||
")
|
")
|
||||||
(_ ""))
|
(_ ""))
|
||||||
(org-babel-expand-body:sql body params)))
|
(org-babel-expand-body:sql body params)
|
||||||
|
;; "sqsh" requires "go" inserted at EOF.
|
||||||
|
(if (string= engine "sqsh") "\ngo" "")))
|
||||||
(org-babel-eval command "")
|
(org-babel-eval command "")
|
||||||
(org-babel-result-cond result-params
|
(org-babel-result-cond result-params
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(progn (insert-file-contents-literally out-file) (buffer-string)))
|
(progn (insert-file-contents-literally out-file) (buffer-string)))
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(cond
|
(cond
|
||||||
((memq (intern engine) '(dbi mysql postgresql))
|
((memq (intern engine) '(dbi mysql postgresql sqsh))
|
||||||
;; Add header row delimiter after column-names header in first line
|
;; Add header row delimiter after column-names header in first line
|
||||||
(cond
|
(cond
|
||||||
(colnames-p
|
(colnames-p
|
||||||
|
@ -239,7 +270,7 @@ SET COLSEP '|'
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
(forward-char -1))
|
(forward-char -1))
|
||||||
(write-file out-file))))
|
(write-file out-file))))
|
||||||
(org-table-import out-file '(16))
|
(org-table-import out-file (if (string= engine "sqsh") '(4) '(16)))
|
||||||
(org-babel-reassemble-table
|
(org-babel-reassemble-table
|
||||||
(mapcar (lambda (x)
|
(mapcar (lambda (x)
|
||||||
(if (string= (car x) header-delim)
|
(if (string= (car x) header-delim)
|
||||||
|
|
Loading…
Reference in a new issue