mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-11-26 07:33:39 +00:00
ob-sql: Fix `case' calls
* lisp/ob-sql.el (org-babel-execute:sql): Replace erroneous `case' call with `pcase'. Small refactoring. Keep lines within 80 characters.
This commit is contained in:
parent
cf8bfc178d
commit
8c2e232b00
105
lisp/ob-sql.el
105
lisp/ob-sql.el
@ -119,45 +119,48 @@ This function is called by `org-babel-execute-src-block'."
|
||||
(out-file (or (cdr (assoc :out-file params))
|
||||
(org-babel-temp-file "sql-out-")))
|
||||
(header-delim "")
|
||||
(command (case (intern engine)
|
||||
('dbi (format "dbish --batch %s < %s | sed '%s' > %s"
|
||||
(command (pcase (intern engine)
|
||||
(`dbi (format "dbish --batch %s < %s | sed '%s' > %s"
|
||||
(or cmdline "")
|
||||
(org-babel-process-file-name in-file)
|
||||
"/^+/d;s/^|//;s/(NULL)/ /g;$d"
|
||||
(org-babel-process-file-name out-file)))
|
||||
('monetdb (format "mclient -f tab %s < %s > %s"
|
||||
(or cmdline "")
|
||||
(org-babel-process-file-name in-file)
|
||||
(org-babel-process-file-name out-file)))
|
||||
('msosql (format "osql %s -s \"\t\" -i %s -o %s"
|
||||
(or cmdline "")
|
||||
(org-babel-process-file-name in-file)
|
||||
(org-babel-process-file-name out-file)))
|
||||
('mysql (format "mysql %s %s %s < %s > %s"
|
||||
(`monetdb (format "mclient -f tab %s < %s > %s"
|
||||
(or cmdline "")
|
||||
(org-babel-process-file-name in-file)
|
||||
(org-babel-process-file-name out-file)))
|
||||
(`msosql (format "osql %s -s \"\t\" -i %s -o %s"
|
||||
(or cmdline "")
|
||||
(org-babel-process-file-name in-file)
|
||||
(org-babel-process-file-name out-file)))
|
||||
(`mysql (format "mysql %s %s %s < %s > %s"
|
||||
(org-babel-sql-dbstring-mysql
|
||||
dbhost dbport dbuser dbpassword database)
|
||||
(if colnames-p "" "-N")
|
||||
(or cmdline "")
|
||||
(or cmdline "")
|
||||
(org-babel-process-file-name in-file)
|
||||
(org-babel-process-file-name out-file)))
|
||||
('postgresql (format
|
||||
"psql --set=\"ON_ERROR_STOP=1\" %s -A -P footer=off -F \"\t\" %s -f %s -o %s %s"
|
||||
(`postgresql (format
|
||||
"psql --set=\"ON_ERROR_STOP=1\" %s -A -P \
|
||||
footer=off -F \"\t\" %s -f %s -o %s %s"
|
||||
(if colnames-p "" "-t")
|
||||
(org-babel-sql-dbstring-postgresql dbhost dbuser database)
|
||||
(org-babel-sql-dbstring-postgresql
|
||||
dbhost dbuser database)
|
||||
(org-babel-process-file-name in-file)
|
||||
(org-babel-process-file-name out-file)
|
||||
(or cmdline "")))
|
||||
('oracle (format
|
||||
"sqlplus -s %s < %s > %s"
|
||||
(org-babel-sql-dbstring-oracle dbhost dbport dbuser dbpassword database)
|
||||
(org-babel-process-file-name in-file)
|
||||
(`oracle (format
|
||||
"sqlplus -s %s < %s > %s"
|
||||
(org-babel-sql-dbstring-oracle
|
||||
dbhost dbport dbuser dbpassword database)
|
||||
(org-babel-process-file-name in-file)
|
||||
(org-babel-process-file-name out-file)))
|
||||
(t (error "No support for the %s SQL engine" engine)))))
|
||||
(_ (error "No support for the %s SQL engine" engine)))))
|
||||
(with-temp-file in-file
|
||||
(insert
|
||||
(case (intern engine)
|
||||
('dbi "/format partbox\n")
|
||||
('oracle "SET PAGESIZE 50000
|
||||
(pcase (intern engine)
|
||||
(`dbi "/format partbox\n")
|
||||
(`oracle "SET PAGESIZE 50000
|
||||
SET NEWPAGE 0
|
||||
SET TAB OFF
|
||||
SET SPACE 0
|
||||
@ -170,42 +173,40 @@ SET MARKUP HTML OFF SPOOL OFF
|
||||
SET COLSEP '|'
|
||||
|
||||
")
|
||||
(t ""))
|
||||
(_ ""))
|
||||
(org-babel-expand-body:sql body params)))
|
||||
(message command)
|
||||
(org-babel-eval command "")
|
||||
(org-babel-result-cond result-params
|
||||
(with-temp-buffer
|
||||
(progn (insert-file-contents-literally out-file) (buffer-string)))
|
||||
(progn (insert-file-contents-literally out-file) (buffer-string)))
|
||||
(with-temp-buffer
|
||||
(cond
|
||||
((or (eq (intern engine) 'mysql)
|
||||
(eq (intern engine) 'dbi)
|
||||
(eq (intern engine) 'postgresql))
|
||||
;; Add header row delimiter after column-names header in first line
|
||||
(cond
|
||||
(colnames-p
|
||||
(with-temp-buffer
|
||||
(insert-file-contents out-file)
|
||||
(goto-char (point-min))
|
||||
(forward-line 1)
|
||||
(insert "-\n")
|
||||
(setq header-delim "-")
|
||||
(write-file out-file)))))
|
||||
(t
|
||||
;; Need to figure out the delimiter for the header row
|
||||
(with-temp-buffer
|
||||
(insert-file-contents out-file)
|
||||
(goto-char (point-min))
|
||||
(when (re-search-forward "^\\(-+\\)[^-]" nil t)
|
||||
(setq header-delim (match-string-no-properties 1)))
|
||||
(goto-char (point-max))
|
||||
(forward-char -1)
|
||||
(while (looking-at "\n")
|
||||
(delete-char 1)
|
||||
(goto-char (point-max))
|
||||
(forward-char -1))
|
||||
(write-file out-file))))
|
||||
((memq (intern engine) '(dbi myslq postgresql))
|
||||
;; Add header row delimiter after column-names header in first line
|
||||
(cond
|
||||
(colnames-p
|
||||
(with-temp-buffer
|
||||
(insert-file-contents out-file)
|
||||
(goto-char (point-min))
|
||||
(forward-line 1)
|
||||
(insert "-\n")
|
||||
(setq header-delim "-")
|
||||
(write-file out-file)))))
|
||||
(t
|
||||
;; Need to figure out the delimiter for the header row
|
||||
(with-temp-buffer
|
||||
(insert-file-contents out-file)
|
||||
(goto-char (point-min))
|
||||
(when (re-search-forward "^\\(-+\\)[^-]" nil t)
|
||||
(setq header-delim (match-string-no-properties 1)))
|
||||
(goto-char (point-max))
|
||||
(forward-char -1)
|
||||
(while (looking-at "\n")
|
||||
(delete-char 1)
|
||||
(goto-char (point-max))
|
||||
(forward-char -1))
|
||||
(write-file out-file))))
|
||||
(org-table-import out-file '(16))
|
||||
(org-babel-reassemble-table
|
||||
(mapcar (lambda (x)
|
||||
|
Loading…
Reference in New Issue
Block a user