I'm trying to link a SQL buffer to SQLi buffer by calling sql-set-sqli-buffer but nothing happens when the function is called. I'm doing this because I want to start muliple SQLi buffers with each of them having their own SQL buffer linked as instructed in C-h f sql-interactive-mode:

Sample session using two connections:

  1. Create first SQLi buffer by calling an entry function.
  2. Rename buffer "SQL" to "Connection 1".
  3. Create a SQL buffer "test1.sql".
  4. Create second SQLi buffer by calling an entry function.
  5. Rename buffer "SQL" to "Connection 2".
  6. Create a SQL buffer "test2.sql".

I did exactly as described above but it doesn't work for me. The linkage is lost when the SQLi buffer is renamed to what other than *SQL*. Apparently the linkage is maintained by a local copy of the variable sql-buffer but the instruction above doesn't seem to reflect how this varaible is set. So I try to do this manually by calling sql-set-sqli-buffer and it still doesn't work.

The version currently used is Emacs 26.2.

  • I think there's missing information in those docs. The sql-mode buffer needs to have the correct product set, or the link between the two buffers can't be set. If you M-x sql-set-product before using M-x sql-set-sqli-buffer does it work?
    – phils
    Commented Dec 16, 2019 at 4:48
  • I wrote emacswiki.org/emacs/SqlQueryBuffer to streamline this kind of thing. Perhaps you'll find that convenient.
    – phils
    Commented Dec 16, 2019 at 4:49
  • There may also be some bugs in 26.2 regarding changing the SQLi buffer after a rename. I've just been testing, and this is working better in 27 than in 26. YMMV.
    – phils
    Commented Dec 16, 2019 at 5:09
  • TBH the example session in the sql-interactive-mode docstring seems misleading to me as well -- it's possible that things haven't worked quite like that for a while. I think this is worth M-x report-emacs-bug -- I see sql-buffer set to nil in general, rather than being "the last SQLi buffer created".
    – phils
    Commented Dec 16, 2019 at 5:14
  • @phils Calling sql-set-product first makes it work. The SqlQueryBuffer snippet also works for me. Thanks! Commented Dec 16, 2019 at 5:45


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.