Skip to content

Commit

Permalink
optionally closes temp files
Browse files Browse the repository at this point in the history
  • Loading branch information
flintforge committed Nov 25, 2024
1 parent b2ce2a7 commit 3bdc1ff
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions ob-sql.el
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@
;; - vertica
;; - saphana
;;
;; Limitations:
;; - session mode provides no error line
;;
;; TODO:
;; - support for more engines
;; - provide babel to SQL
;; - babel tables as input
;; - expand body for sessions
;; - convention for ob- prefix ?

;;; Code:

Expand All @@ -87,6 +91,7 @@
(sql-set-product-feature 'sqlite :terminal-command "\\.")

(sql-set-product-feature 'postgres :prompt-regexp "SQL> ")
(sql-set-product-feature 'postgres :prompt-cont-regexp "> ")
(sql-set-product-feature 'postgres :batch-terminate
(format "\\echo %s\n" ob-sql-session--batch-end-indicator))
(sql-set-product-feature 'postgres :terminal-command "\\\\")
Expand Down Expand Up @@ -137,6 +142,13 @@
(dbinstance . :any))
"HEADER arguments accepted.")

(defcustom org-babel-sql-close-out-temp-buffer-p 'nil
"Close sql-out-temp buffer."
:type '(boolean)
:group 'org-babel-sql
:safe t)


(defun org-babel-sql-dbstring-mysql (host port user password database)
"Make MySQL command line arguments for database connection.
Pass nil to omit arguments."
Expand Down Expand Up @@ -459,8 +471,7 @@ SET COLSEP '|'
(delete-char 1)
(goto-char (point-max))
(forward-char -1))
(write-file out-file)
)))
(write-file out-file))))

(when session-p
(goto-char (point-min))
Expand All @@ -471,6 +482,8 @@ SET COLSEP '|'
(replace-match "")))

(org-table-import out-file (if (string= engine "sqsh") '(4) '(16)))
(when org-babel-sql-close-out-temp-buffer-p
(kill-buffer (get-file-buffer out-file)))
(org-babel-reassemble-table
(mapcar (lambda (x)
(if (string= (car x) header-delim)
Expand Down

0 comments on commit 3bdc1ff

Please sign in to comment.