Subject: Re: 24.4; sql-connect fails in first invocation: "Attempt to set a constant symbol: nil"

From: Nikolay Kudryavtsev <[email-masked]>
Date: Mon, 25 Jul 2016 23:12:47 +0300

Ok, this bug has been bugging me long enough.

What happens is that there's a dynamic let block that looks like this:

(eval `(let ((,param-var ',rem-params))
                          (sql-product-interactive ',sql-product 
',new-name))))

Here's the code that sets param-var:

(setq param-var
           (sql-get-product-feature sql-product :sqli-login nil t))

It uses global variable sql-product. The default sql-product is ansi and 
running the above for it results in nil. Running "(let ((nil ..." leads 
to this error. In the same function there is a block that sets it to a 
proper value based on the current connection, but it is executed after 
param-var is already set. That's why the second time works.

I've attached a simple patch that just reorders code within sql-connect.

-- 
Best Regards,
Nikolay Kudryavtsev

diff --git lisp/progmodes/sql.el lisp/progmodes/sql.el
index fd59f46..a6e7ec4 100644
--- lisp/progmodes/sql.el
+++ lisp/progmodes/sql.el
@@ -4040,6 +4040,12 @@ sql-connect
           (if connect-set
               ;; Set the desired parameters
               (let (param-var login-params set-params rem-params)
+                ;; Set the parameters and start the interactive session
+                (mapc
+                 #'(lambda (vv)
+                     (set-default (car vv) (eval (cadr vv))))
+                 (cdr connect-set))
+                (setq-default sql-connection connection)

                 ;; :sqli-login params variable
                 (setq param-var
@@ -4069,13 +4075,6 @@ sql-connect
                            (unless (member token set-params)
                              (if plist (cons token plist) token)))))

-                ;; Set the parameters and start the interactive session
-                (mapc
-                 #'(lambda (vv)
-                     (set-default (car vv) (eval (cadr vv))))
-                 (cdr connect-set))
-                (setq-default sql-connection connection)
-
                 ;; Start the SQLi session with revised list of login parameters
                 (eval `(let ((,param-var ',rem-params))
                          (sql-product-interactive ',sql-product ',new-name))))