Function: sql-execute
sql-execute is a byte-compiled function defined in sql.el.gz.
Signature
(sql-execute SQLBUF OUTBUF COMMAND ENHANCED ARG)
Documentation
Execute a command in a SQL interactive buffer and capture the output.
The commands are run in SQLBUF and the output saved in OUTBUF. COMMAND must be a string, a function or a list of such elements. Functions are called with SQLBUF, OUTBUF and ARG as parameters; strings are formatted with ARG and executed.
If the results are empty the OUTBUF is deleted, otherwise the buffer is popped into a view window.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/sql.el.gz
(defun sql-execute (sqlbuf outbuf command enhanced arg)
"Execute a command in a SQL interactive buffer and capture the output.
The commands are run in SQLBUF and the output saved in OUTBUF.
COMMAND must be a string, a function or a list of such elements.
Functions are called with SQLBUF, OUTBUF and ARG as parameters;
strings are formatted with ARG and executed.
If the results are empty the OUTBUF is deleted, otherwise the
buffer is popped into a view window."
(mapc
(lambda (c)
(cond
((stringp c)
(sql-redirect sqlbuf (if arg (format c arg) c) outbuf) t)
((functionp c)
(apply c sqlbuf outbuf enhanced arg nil))
(t (error "Unknown sql-execute item %s" c))))
(if (consp command) command (cons command nil)))
(setq outbuf (get-buffer outbuf))
(if (zerop (buffer-size outbuf))
(kill-buffer outbuf)
(let ((one-win (eq (selected-window)
(get-lru-window))))
(with-current-buffer outbuf
(set-buffer-modified-p nil)
(setq-local revert-buffer-function
(lambda (_ignore-auto _noconfirm)
(sql-execute sqlbuf (buffer-name outbuf)
command enhanced arg)))
(special-mode))
(pop-to-buffer outbuf)
(when one-win
(shrink-window-if-larger-than-buffer)))))