sql-set-sqli-buffer "there is no suitable sqli buffer"
Asked Answered
C

1

10

I'm new to emacs and not very used to lisp so this is probably a newby error but i can't find the solution.

I try to install the sql mode to interact with my mysql DB.

To do so, I modified the sql.el file to precise the sql-user, sql-password, sql-database, sql-server, and sql-port option, added the port in the sql-mysql-login-params

I launch emacs and M-x sql-mysql

the mode change to SQLi[MySQL]:run

I change buffer, M-x find-file myfile.sql

This buffer is in SQL[ANSI] mode

Then i C-c C-r a sql statement and have the error "No SQL Process started"

As said somewhere, I M-x sql-set-sqli-buffer but i have the error "There is no suitable SQLi buffer"

For this, I can't find the solution... What did I miss ?

I use emacs 24.2.1

edit : when I execute a select statement directly in the SQLi[MySQL]:run buffer, it returns rows as expected...

Shouldn't the other buffer be in SQL[MySQL] mode ?

Colossus answered 4/1, 2013 at 9:9 Comment(0)
P
17

I think you're quite right, the reason that sql-set-sqli-buffer is not finding a suitable SQLi buffer is because it takes the product subtype of the SQL-mode buffer into account when walking through the list of open buffers.

Here's the code for the buffer testing from my copy of sql.el, which shipped with my emacs ( version - GNU emacs 24.2.1

(defun sql-find-sqli-buffer (&optional product connection)
  "Returns the name of the current default SQLi buffer or nil.
In order to qualify, the SQLi buffer must be alive, be in
`sql-interactive-mode' and have a process."
  (let ((buf  sql-buffer)
        (prod (or product sql-product)))
    (or
     ;; Current sql-buffer, if there is one.
     (and (sql-buffer-live-p buf prod connection)
          buf)
     ;; Global sql-buffer
     (and (setq buf (default-value 'sql-buffer))
          (sql-buffer-live-p buf prod connection)
          buf)
     ;; Look thru each buffer
     (car (apply 'append
                 (mapcar (lambda (b)
                           (and (sql-buffer-live-p b prod connection)
                                (list (buffer-name b))))
                         (buffer-list)))))))

the two values used to primarily used to test eligibility are a buffer and a symbol identifying the product type. This symbol is passed in as an argument, or defaults to the value of sql-product. It appears that sql-product, unless set in some other way is defaulted to 'ansi, which is why your editing buffer is SQL[ANSI].

You should try setting the product type in this buffer (e.g. with M-x sql-set-product) before trying to associate a SQLi buffer with the query buffer. If you want the default to always be 'mysql' you can set this in your init file, or customize it using M-x customize-variable

SQL-mode is quite order dependent on having the buffer set up with the right local variables in order to have a working associated iSQL session.

A typical sequence I use to initiate an iSQL buffer with a query in another buffer I am already editing is as follows

  1. Switch to a buffer with the SQL text in it , by visiting a file perhaps, or using C-x b to create a temporary buffer.
  2. Set this buffer to be in the correct SQL type, with M-x sql-set-product and then entering a known type , such as "mysql" at the prompt.
  3. Hitting C-c <TAB> (bound to sql-product-interactive) to switch to an iSQL buffer associated to this buffer, potentially by locating or creating an new comint process

It is probably worth reading the output of the M-x sql-help command. The documentation for SQL-mode is very light. I've figured out what little I know about it mostly from reading the source.

Preshrunk answered 14/1, 2013 at 16:39 Comment(5)
Thanks for the answer. I used to be able to just M-x sql-mode on a buffer I'd create with C-x b, and it would do the right thing. Now I have to M-x sql-mode RET M-x sql-set-product RET "postgres" RET. Presumably sql-find-sqli-buffer code changed in Emacs 24.Meretricious
Actually, that still gives me a "No SQL process started" error in the mini-buffer when I try to C-c C-c. :/Meretricious
even with a sql-postgres SQLi buffer already running? I think SQL mode has perhaps changed a bit for emacs 24, because I've returned to using a little, after a while away, and it does seem a bit crankier. Does my 1-2-3 example not work for you either (substituting postgres for mysql) ?Preshrunk
nope, it doesn't. I need to perform this dance for it to work, where the order does matter: paste.lisp.org/display/134684#3Meretricious
Thanks @felideon. 4 years later and this still doesn't work as documented, but requires settings both sql-product and calling sql-set-sqli-buffer. FWIW, you can customize sql-product to skip this step.Martini

© 2022 - 2024 — McMap. All rights reserved.