|
@@ -43,15 +43,24 @@
|
|
|
;; - colnames (default, nil, means "yes")
|
|
|
;; - result-params
|
|
|
;; - out-file
|
|
|
+;;
|
|
|
;; The following are used but not really implemented for SQL:
|
|
|
;; - colname-names
|
|
|
;; - rownames
|
|
|
;; - rowname-names
|
|
|
;;
|
|
|
+;; Engines supported:
|
|
|
+;; - mysql
|
|
|
+;; - dbi
|
|
|
+;; - mssql
|
|
|
+;; - sqsh
|
|
|
+;; - postgresql
|
|
|
+;; - oracle
|
|
|
+;;
|
|
|
;; TODO:
|
|
|
;;
|
|
|
;; - 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?
|
|
|
;;
|
|
|
|
|
@@ -116,6 +125,18 @@ SQL Server on Windows and Linux platform."
|
|
|
(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)
|
|
|
"Convert the file name to OS standard.
|
|
|
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 out-file)
|
|
|
(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
|
|
|
"sqlplus -s %s < %s > %s"
|
|
|
(org-babel-sql-dbstring-oracle
|
|
@@ -203,18 +232,20 @@ SET MARKUP HTML OFF SPOOL OFF
|
|
|
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-result-cond result-params
|
|
|
(with-temp-buffer
|
|
|
(progn (insert-file-contents-literally out-file) (buffer-string)))
|
|
|
(with-temp-buffer
|
|
|
(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
|
|
|
(cond
|
|
|
(colnames-p
|
|
@@ -239,7 +270,7 @@ SET COLSEP '|'
|
|
|
(goto-char (point-max))
|
|
|
(forward-char -1))
|
|
|
(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
|
|
|
(mapcar (lambda (x)
|
|
|
(if (string= (car x) header-delim)
|