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 ?
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
C-x b
to create a temporary buffer. M-x sql-set-product
and then entering a known type , such as "mysql" at the prompt.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 processIt 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With