[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: help with using sql-connect
From: |
Alex Kost |
Subject: |
Re: help with using sql-connect |
Date: |
Wed, 17 Dec 2014 22:49:27 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
Luca Ferrari (2014-12-17 12:07 +0300) wrote:
> Hi all,
> I'm trying to write down a simpler configuration for connecting to a
> few database:
>
> (setq sql-connection-alist
> '((TEST (sql-product 'postgres)
> (sql-port 5432)
> (sql-server "localhost")
> (sql-user "demo")
> (sql-password "demo")
> (sql-database "demodb"))
> (PROD (sql-product 'postgres)
> (setq sql-port 5432)
> (sql-user "demo")
> (sql-password "demo")
> (sql-database "demodb") ) ) )
>
>
> (defun pg-connect (which)
> (interactive "sWhich database?" )
> (setq sql-product 'postgres)
> (let ()
> (message "Connecting to %s" which)
> (sql-connect which ) ) )
>
>
> The problem is that no matter what connection name I pass to
> pg-connect, it always answers me that "SQL Connection <TEST> does not
> exist".
> I suspect the problem is that sql-connect expects a symbol, but even
> wrapping "which" with (symbol-name) does not help.
> What am I missing?
No the problem is not in a symbol - a string should work. At least I've
tested your code and it worked. Are you sure "sql-connection-alist"
contains the value you expect?
Also do you really need your "pg-connect"? You can just use "M-x
sql-connect". However if you needed it, you may take an "interactive"
part of `sql-connect' to make completions available, so your function
may look like this:
(defun pg-connect (which)
(interactive
(list (sql-read-connection "Which database? ")))
(message "Connecting to %S" which)
(sql-connect which))
--
Alex