Can you create a new SQL buffer in Emacs if one already exists?
Asked Answered
A

3

5

Let's say you have a *SQL* buffer already open in Emacs that is connected to a specific server and database. Now, your intention is to connect to a different server and database while keeping your other SQL buffer process active.

How exactly can you create a new *SQL* buffer process without killing your original SQL buffer? Can this be done? Is there a way to instead change your connection info for the existing buffer?

Ashok answered 17/2, 2009 at 18:58 Comment(0)
A
8

Running:

M-x sql-rename-buffer

On a connected *SQL* buffer will rename the current buffer after the current connection. So:

*SQL*

Becomes:

*SQL user/database*

You can then do:

M-x sql-mysql

Or whatever your flavor of DB is to create another SQL buffer.

Afar answered 17/2, 2009 at 19:29 Comment(0)
H
2

As a slight simplification, you can just do:

(add-hook 'sql-interactive-mode-hook 'sql-rename-buffer)

(I.e., you don't need the lambda).

Hannibal answered 20/2, 2009 at 20:38 Comment(0)
V
1

In addition, if someone like me likes another representation of the connection, here is mine. This is how my sql buffers named: "driver://user@server/database"


(defun sql-make-alternate-buffer-name ()
  (concat (concat (prin1-to-string sql-interactive-product) "://")
      (if (string= "" sql-user)
          (if (string= "" (user-login-name))
          ()
        (concat (user-login-name) "/"))
        (concat sql-user "@"))
      (concat sql-server "/")
      (if (string= "" sql-database)
          (if (string= "" sql-server)
          (system-name)
        sql-server)
        sql-database)))

SQL buffers created in sql-interactive-mode, which runs sql-interactive-mode-hook, so there is no need to run sql-rename-buffer manually


(add-hook 'sql-interactive-mode-hook
    (lambda () (sql-rename-buffer)))
Viridian answered 19/2, 2009 at 17:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.