Forum OpenACS Q&A: Re: psql and emacs

Collapse
12: Re: psql and emacs (response to 1)
Posted by Torben Brosten on
I am unable to find a way to use gnu-emacs sql-postgres to connect directly to db.

The connection must specify port, host, dbname and username, but apparently sql-postgres only asks for host and dbname. Is there pathname short-hand I can use to get around this?

Besides M-x sql-help, I was not able to find docs for using sql-postgres (I tried gnu.org/emacs and google). Postgres.org mentions a non-enduser, socket-level pg.el.[1] where port and username defaults can be changed.

In the interim, I am using psql via M-x shell, but am experiencing the same symptoms as original post above: At the end of each screen, a prompt appears which partially destroys the data output of a view row. I tried the techniques mentioned above, but they don't seem to work. I get syntax errors. Maybe the command has changed in the newer versions, or the instructions are not explicit enough for me to understand?

1. http://www.chez.com/emarsden/downloads/pg.el

Collapse
18: Re: psql and emacs (response to 12)
Posted by Andrei Popov on
From my .emacs:
(setq sql-user "apopov")
(setq sql-database "apopov")
(setq sql-server "vm")
(setq sql-postgres-options '("-Uapopov" "-P" "pager=off"))
But it won't help w/port.
Collapse
19: Re: psql and emacs (response to 18)
Posted by Bart Teeuwisse on
Another option is to apply the following patch to emacs/21.2/lisp/progmodes/sql.el so that Emacs will always ask for a username regardless of environment variables. It has served me well.

1674c1674
<    (sql-get-login 'database 'server)
---
<blockquote>    (sql-get-login 'user 'database 'server)
</blockquote>
1683a1684,1685
<blockquote>      (if (not (string= "" sql-user))
      (setq params (append (list "-U" sql-user) params)))
</blockquote>

Don't forget to byte compile sql.el afterwards or Emacs will continue to use the old sql.elc without the patch.

/Bart

Collapse
20: Re: psql and emacs (response to 19)
Posted by Mark Aufflick on
To save people wasting the time i just wasted, if you're using emacs 21.3 you can do just about the same thing as Bart describes with the following points:

* I applied the patch by hand, but I think the lines in the 21.2 patch above is off by 1 - but get to line 1683 and it's around there somewhere
* it only worked for me if the sql-get-login used this specific order:

(sql-get-login 'database 'user 'server)

If I put the 'user anywhere else it ignored it :/

Also, sql-get-login will automatically ask for password when it asks for user - if you are not using passwords just leave it blank and hit enter.

PS: Bart you'll be pleased to know that I got to this thread from the first page of a google search - it's cool because I'm working at a non-oacs client, and I didn't even notice that I was on openacs.org until I saw /Bart :)

I'll be signing off /Mark soon, thus completing all our conversions into Lars-borgs :P