I looked at sqsh and think it would have the same issue with escaping,
although I also don't have a setup I can test with fully. The attached
patch removes the quoting for mssql and sqsh, updates the existing unit
tests to match, and adds some new unit tests to explicitly exercise
characters that the shell would interpret if not escaped.

Cheers,

Derek

On Thu, Sep 3, 2026 at 6:53 AM Derek Chen-Becker <[email protected]>
wrote:

> Thanks for reporting this, I can take a look.
>
> Owned.
>
> On Tue, Sep 1, 2026 at 12:54 PM <[email protected]> wrote:
>
>>
>> Commit 959534ba1149bb29b1c731b34df9a339a54753e6 introduces a regression
>> for the mssql dialect.
>>
>> The referenced discussion:
>>
>> https://list.orgmode.org/orgmode/du2p193mb24225f623dbf8b3d254d3c0e88...@du2p193mb2422.eurp193.prod.outlook.com/
>>
>>
>> This commit double escapes the mssql (and possibly the sqsh dialect, but
>> I have no way of testing) parameters.  For example to log into mssql you
>> supply a host name as well: user@host. I'm unsure of internally what's
>> going on exactly, but with this commit the username sent is user\@host
>> which is interpreted as a Windows login and is incorrect.
>>
>> This is also an issue with passwords that contain special characters.
>>
>> Instead we can remove the escaped quotes around the string and rely on
>> shell-quote-argument to do the proper escaping. Any additional escaping
>> can be left up to the user.
>>
>>
>>
>> diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
>> index 3f6fdf553..5f1363693 100644
>> --- a/lisp/ob-sql.el
>> +++ b/lisp/ob-sql.el
>> @@ -168,10 +168,10 @@ using its alias."
>>  SQL Server on Windows and Linux platform."
>>    (mapconcat #'identity
>>              (delq nil
>> -                  (list (when host (format "-S \"%s\""
>> (shell-quote-argument host)))
>> -                        (when user (format "-U \"%s\""
>> (shell-quote-argument user)))
>> -                        (when password (format "-P \"%s\""
>> (shell-quote-argument password)))
>> -                        (when database (format "-d \"%s\""
>> (shell-quote-argument database)))))
>> +                  (list (when host (format "-S %s" (shell-quote-argument
>> host)))
>> +                        (when user (format "-U %s" (shell-quote-argument
>> user)))
>> +                        (when password (format "-P %s"
>> (shell-quote-argument password)))
>> +                        (when database (format "-d %s"
>> (shell-quote-argument database)))))
>>              " "))
>>
>>  (defun org-babel-sql-dbstring-sqsh (host user password database)
>>
>>
>
> --
> +---------------------------------------------------------------+
> | Derek Chen-Becker                                             |
> | GPG Key available at https://keybase.io/dchenbecker and       |
> | https://pgp.mit.edu/pks/lookup?search=derek%40chen-becker.org |
> | Fngrprnt: EB8A 6480 F0A3 C8EB C1E7  7F42 AFC5 AFEE 96E4 6ACC  |
> +---------------------------------------------------------------+
>
>

-- 
+---------------------------------------------------------------+
| Derek Chen-Becker                                             |
| GPG Key available at https://keybase.io/dchenbecker and       |
| https://pgp.mit.edu/pks/lookup?search=derek%40chen-becker.org |
| Fngrprnt: EB8A 6480 F0A3 C8EB C1E7  7F42 AFC5 AFEE 96E4 6ACC  |
+---------------------------------------------------------------+

Attachment: 0001-lisp-ob-sql.el-Fix-escaping-for-mssql-and-sqsh-argum.patch
Description: Binary data

Reply via email to