Function: sql-get-login

sql-get-login is a byte-compiled function defined in sql.el.gz.

Signature

(sql-get-login &rest WHAT)

Documentation

Get username, password and database from the user.

The variables sql-user, sql-password, sql-server, and sql-database can be customized. They are used as the default values. Usernames, servers and databases are stored in sql-user-history, sql-server-history and database-history. Passwords are not stored in a history.

Parameter WHAT is a list of tokens passed as arguments in the function call. The function asks for the username if WHAT contains the symbol user, for the password if it contains the symbol password, for the server if it contains the symbol server, and for the database if it contains the symbol database. The members of WHAT are processed in the order in which they are provided.

If the sql-password-wallet is non-nil and WHAT contains the password token, then the password token will be pushed to the end to be sure that all of the values can be fed to the wallet.

Each token may also be a list with the token in the car and a plist of options as the cdr. The following properties are supported:

    :file <filename-regexp>
    :completion <list-of-strings-or-function>
    :default <default-value>
    :number t

In order to ask the user for username, password and database, call the function like this: (sql-get-login 'user 'password 'database).

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/sql.el.gz
(defun sql-get-login (&rest what)
  "Get username, password and database from the user.

The variables `sql-user', `sql-password', `sql-server', and
`sql-database' can be customized.  They are used as the default values.
Usernames, servers and databases are stored in `sql-user-history',
`sql-server-history' and `database-history'.  Passwords are not stored
in a history.

Parameter WHAT is a list of tokens passed as arguments in the
function call.  The function asks for the username if WHAT
contains the symbol `user', for the password if it contains the
symbol `password', for the server if it contains the symbol
`server', and for the database if it contains the symbol
`database'.  The members of WHAT are processed in the order in
which they are provided.

If the `sql-password-wallet' is non-nil and WHAT contains the
`password' token, then the `password' token will be pushed to the
end to be sure that all of the values can be fed to the wallet.

Each token may also be a list with the token in the car and a
plist of options as the cdr.  The following properties are
supported:

    :file <filename-regexp>
    :completion <list-of-strings-or-function>
    :default <default-value>
    :number t

In order to ask the user for username, password and database, call the
function like this: (sql-get-login \\='user \\='password \\='database)."

  ;; Push the password to the end if we have a wallet
  (when (and sql-password-wallet
             (fboundp sql-password-search-wallet-function)
             (member 'password what))
    (setq what (append (cl-delete 'password what)
                       '(password))))

  ;; Prompt for each parameter
  (dolist (w what)
    (let ((plist (cdr-safe w)))
      (pcase (or (car-safe w) w)
        ('user
         (sql-get-login-ext 'sql-user "User" 'sql-user-history plist))

        ('password
         (setq-default sql-password
                       (if (and sql-password-wallet
                                (fboundp sql-password-search-wallet-function))
                           (let ((password (funcall sql-password-search-wallet-function
                                                    sql-password-wallet
                                                    sql-product
                                                    sql-user
                                                    sql-server
                                                    sql-database
                                                    sql-port)))
                             (if password
                                 password
                               (read-passwd "Password: " nil (sql-default-value 'sql-password))))
                         (read-passwd "Password: " nil (sql-default-value 'sql-password)))))

        ('server
         (sql-get-login-ext 'sql-server "Server" 'sql-server-history plist))

        ('database
         (sql-get-login-ext 'sql-database "Database"
                            'sql-database-history plist))

        ('port
         (sql-get-login-ext 'sql-port "Port"
                            nil (append '(:number t) plist)))))))