Function: sql-make-alternate-buffer-name
sql-make-alternate-buffer-name is a byte-compiled function defined in
sql.el.gz.
Signature
(sql-make-alternate-buffer-name &optional PRODUCT)
Documentation
Return a string that can be used to rename a SQLi buffer.
This is used to set sql-alternate-buffer-name within
sql-interactive-mode.
If the session was started with sql-connect then the alternate
name would be the name of the connection.
Otherwise, it uses the parameters identified by the :sqlilogin parameter.
If all else fails, the alternate name would be the user and server/database name.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/sql.el.gz
(defun sql-make-alternate-buffer-name (&optional product)
"Return a string that can be used to rename a SQLi buffer.
This is used to set `sql-alternate-buffer-name' within
`sql-interactive-mode'.
If the session was started with `sql-connect' then the alternate
name would be the name of the connection.
Otherwise, it uses the parameters identified by the :sqlilogin
parameter.
If all else fails, the alternate name would be the user and
server/database name."
(let ((name ""))
;; Build a name using the :sqli-login setting
(setq name
(apply #'concat
(cdr
(apply #'append nil
(sql-for-each-login
(sql-get-product-feature (or product sql-product) :sqli-login)
(lambda (token plist)
(pcase token
('user
(unless (string= "" sql-user)
(list "/" sql-user)))
('port
(unless (or (not (numberp sql-port))
(= 0 sql-port))
(list ":" (number-to-string sql-port))))
('server
(unless (string= "" sql-server)
(list "."
(if (plist-member plist :file)
(file-name-nondirectory sql-server)
sql-server))))
('database
(unless (string= "" sql-database)
(list "@"
(if (plist-member plist :file)
(file-name-nondirectory sql-database)
sql-database))))
;; (`password nil)
(_ nil))))))))
;; If there's a connection, use it and the name thus far
(if sql-connection
(format "<%s>%s" sql-connection (or name ""))
;; If there is no name, try to create something meaningful
(if (string= "" (or name ""))
(concat
(if (string= "" sql-user)
(if (string= "" (user-login-name))
()
(concat (user-login-name) "/"))
(concat sql-user "/"))
(if (string= "" sql-database)
(if (string= "" sql-server)
(system-name)
sql-server)
sql-database))
;; Use the name we've got
name))))