I use Sql-mode to connect to an Oracle database. The default settings for linesize and pagesize, and colsep are not ideal, so I'd like to have Emacs automatically run the following commands upon connecting to my databases:
SET COLSEP "|"
SET LINESIZE 9999
SET PAGESIZE 9999
How can I accomplish this?
Adapted from an earlier answer by Tobias, which correctly pointed out the use of
sql-login-hook
to send the SQL via comint functions.With Postgres I needed to send each command separately, so here I've used
comint-send-string
to do that (and sql.el maintainer Michael has indicated that this is indeed the preferred method).Note also that as the same
sql-login-hook
is used with all database products, it's a good idea to checksql-product
before sending product-specific commands. I've included the check for Oracle in this instance.Note that you should include a newline at the end of the command, to replicate typing RET when submitting a command interactively. (If you don't do this, the command(s) will still have been 'typed', but will not take effect until you manually type RET at the prompt).
If this still isn't working, take note that
sql-login-hook
is only run bysql-product-interactive
if it recognises the interactive SQL prompt in the buffer. This prompt is matched using the regular expressionsql-prompt-regexp
(which is established using the per-product defaults insql-product-alist
). If the default pattern does not match your prompts, you can modify it insql-interactive-mode-hook
.For example, the following allows Postgres prompts to include symbol-constituent characters (such as an underscore
_
) in the database name, as well as word-constituent characters: