all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* help with using sql-connect
@ 2014-12-17  9:07 Luca Ferrari
  2014-12-17 19:49 ` Alex Kost
  0 siblings, 1 reply; 7+ messages in thread
From: Luca Ferrari @ 2014-12-17  9:07 UTC (permalink / raw)
  To: help-gnu-emacs

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?

Thanks,
Luca



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: help with using sql-connect
  2014-12-17  9:07 help with using sql-connect Luca Ferrari
@ 2014-12-17 19:49 ` Alex Kost
  2014-12-18  7:54   ` Luca Ferrari
  0 siblings, 1 reply; 7+ messages in thread
From: Alex Kost @ 2014-12-17 19:49 UTC (permalink / raw)
  To: Luca Ferrari; +Cc: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: help with using sql-connect
  2014-12-17 19:49 ` Alex Kost
@ 2014-12-18  7:54   ` Luca Ferrari
  2014-12-18  9:12     ` Thien-Thi Nguyen
  0 siblings, 1 reply; 7+ messages in thread
From: Luca Ferrari @ 2014-12-18  7:54 UTC (permalink / raw)
  To: Alex Kost; +Cc: help-gnu-emacs

Ciao Alex,

On Wed, Dec 17, 2014 at 8:49 PM, Alex Kost <alezost@gmail.com> wrote:
> 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?


Uhm...I paste again my sql-connection-alist for double check:

(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") ) ) )


However if I try directly M-x sql-connect then no matter whatever I
write, I got always an error saying
Invalid function: (TEST PROD)
If I try your snippet of code for pg-connect I got the same error. So
I suspect there is something wrong with the sql-connection-alist, but
I cannot see what.
I'm running 24.3.1, if that matters.

Thanks,
Luca



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: help with using sql-connect
  2014-12-18  7:54   ` Luca Ferrari
@ 2014-12-18  9:12     ` Thien-Thi Nguyen
  2014-12-18 11:20       ` Luca Ferrari
  0 siblings, 1 reply; 7+ messages in thread
From: Thien-Thi Nguyen @ 2014-12-18  9:12 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 609 bytes --]

() Luca Ferrari <fluca1978@infinito.it>
() Thu, 18 Dec 2014 08:54:09 +0100

   I suspect there is something wrong with the
   sql-connection-alist, but I cannot see what.

I see from ‘C-h v sql-connection-alist RET’ that
the alist keys are called CONNECTION, and that:

 CONNECTION is a case-insensitive string identifying
 the connection

Do you see differently?

-- 
Thien-Thi Nguyen
   GPG key: 4C807502
   (if you're human and you know it)
      read my lisp: (responsep (questions 'technical)
                               (not (via 'mailing-list)))
                     => nil

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: help with using sql-connect
  2014-12-18  9:12     ` Thien-Thi Nguyen
@ 2014-12-18 11:20       ` Luca Ferrari
  2014-12-18 12:01         ` Thien-Thi Nguyen
  0 siblings, 1 reply; 7+ messages in thread
From: Luca Ferrari @ 2014-12-18 11:20 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, Dec 18, 2014 at 10:12 AM, Thien-Thi Nguyen <ttn@gnu.org> wrote:
> () Luca Ferrari <fluca1978@infinito.it>
> () Thu, 18 Dec 2014 08:54:09 +0100
>
>    I suspect there is something wrong with the
>    sql-connection-alist, but I cannot see what.
>
> I see from ‘C-h v sql-connection-alist RET’ that
> the alist keys are called CONNECTION, and that:
>
>  CONNECTION is a case-insensitive string identifying
>  the connection
>
> Do you see differently?

On emacs 24.3.1 I see:

Where CONNECTION is a symbol identifying the connection, SQL-VARIABLE
is the symbol name of a SQL mode variable, and VALUE is the value to
be assigned to the variable.

Something must have changed in the meantime. However, even trying
case-insensitive connection names did not solved the problem on the
older emacs.
Ok, enough for me to upgrade also this last machine!

Thanks,
Luca



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: help with using sql-connect
  2014-12-18 11:20       ` Luca Ferrari
@ 2014-12-18 12:01         ` Thien-Thi Nguyen
  2014-12-18 12:44           ` Luca Ferrari
  0 siblings, 1 reply; 7+ messages in thread
From: Thien-Thi Nguyen @ 2014-12-18 12:01 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 629 bytes --]

() Luca Ferrari <fluca1978@infinito.it>
() Thu, 18 Dec 2014 12:20:43 +0100

   Where CONNECTION is a symbol identifying the connection

I seem to recall that the original code used

 (interactive "sPROMPT?")

That arranges for the var to be assigned a string value.
Perhaps you can try:

 (interactive "SPROMPT?")

instead (NB: uppercase "S").  ‘C-h v interactive RET’ for details.

-- 
Thien-Thi Nguyen
   GPG key: 4C807502
   (if you're human and you know it)
      read my lisp: (responsep (questions 'technical)
                               (not (via 'mailing-list)))
                     => nil

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: help with using sql-connect
  2014-12-18 12:01         ` Thien-Thi Nguyen
@ 2014-12-18 12:44           ` Luca Ferrari
  0 siblings, 0 replies; 7+ messages in thread
From: Luca Ferrari @ 2014-12-18 12:44 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, Dec 18, 2014 at 1:01 PM, Thien-Thi Nguyen <ttn@gnu.org> wrote:
>  (interactive "SPROMPT?")

Great! It worked on 24.3.

Thanks,
Luca



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-12-18 12:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-17  9:07 help with using sql-connect Luca Ferrari
2014-12-17 19:49 ` Alex Kost
2014-12-18  7:54   ` Luca Ferrari
2014-12-18  9:12     ` Thien-Thi Nguyen
2014-12-18 11:20       ` Luca Ferrari
2014-12-18 12:01         ` Thien-Thi Nguyen
2014-12-18 12:44           ` Luca Ferrari

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.