From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?Q?Johan_W=2E_Kl=C3=BCwer?= Subject: ob-sql.el: org-babel-process-file-name for MSSQL Date: Tue, 10 Mar 2020 21:18:56 +0100 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000f34a2805a085d416" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:51266) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBlLK-0000ES-4l for emacs-orgmode@gnu.org; Tue, 10 Mar 2020 16:19:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBlLI-00034Z-My for emacs-orgmode@gnu.org; Tue, 10 Mar 2020 16:19:09 -0400 Received: from mail-qk1-x72a.google.com ([2607:f8b0:4864:20::72a]:38208) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jBlLI-00033e-I8 for emacs-orgmode@gnu.org; Tue, 10 Mar 2020 16:19:08 -0400 Received: by mail-qk1-x72a.google.com with SMTP id h14so8134073qke.5 for ; Tue, 10 Mar 2020 13:19:08 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane-mx.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --000000000000f34a2805a085d416 Content-Type: text/plain; charset="UTF-8" I need to query MS Sql Server (running in Docker, Ubuntu) from org-babel. The file name for temporary files that ob-sql assembles doesn't work -- we get, e.g., c\:/tmp/babel-Pey8i9/sql-in-dhrGdF which produces the error Sqlcmd: Error: Error occurred while opening or operating on file c: (Reason: Access is denied). while the following string works (use backslashes, add quotes). "c:\tmp\babel-Pey8i9\sql-in-yQfz4K" I'm not sure of the best way to submit this. The following change to ob-sql.el works for me, but maybe it wouldn't in other setups with Sql Server. (`mssql (format "sqlcmd %s -s \"\t\" %s -i \"%s\" -o \"%s\"" (or cmdline "") (org-babel-sql-dbstring-mssql dbhost dbuser dbpassword database) (org-babel-sql-convert-standard-filename (replace-regexp-in-string "/" (regexp-quote "\\") (replace-regexp-in-string "c\\\\" "c" (org-babel-process-file-name in-file)))) (org-babel-sql-convert-standard-filename (replace-regexp-in-string "/" (regexp-quote "\\") (replace-regexp-in-string "c\\\\" "c" (org-babel-process-file-name out-file)))))) Johan --000000000000f34a2805a085d416 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I need to query MS Sql Server (running in Docker, Ubu= ntu) from org-babel. The file name for temporary files that ob-sql assemble= s doesn't work -- we get, e.g.,

=C2=A0 c\= :/tmp/babel-Pey8i9/sql-in-dhrGdF

which produces th= e error

=C2=A0 Sqlcmd: Error: Error occurred while= opening or operating on file c: (Reason: Access is denied).

=
while the following string works (use backslashes, add quotes).<= br>

=C2=A0 "c:\tmp\babel-Pey8i9\sql-in-yQfz4K= "


I'm not sure of the best= way to submit this. The following change to ob-sql.el works for me, but ma= ybe it wouldn't in other setups with Sql Server.

=C2=A0=C2=A0 (`mssql (format "sqlcmd %s -s \"\t\" = %s -i \"%s\" -o \"%s\""
=C2=A0 =C2=A0(or c= mdline "")
=C2=A0 =C2=A0(org-babel-sql-dbstring-mssql
= =C2=A0 =C2=A0 dbhost dbuser dbpassword database)
=C2=A0 =C2=A0= (org-babel-sql-convert-standard-filename
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0(replace-regexp-in-string "/" (regexp-quote &quo= t;\\")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(replace-regexp-in-string "c\\\\" "c"
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-babel-process-file-name in-file))))<= br> =C2=A0 =C2=A0(org-babel-sql-convert-standard-filename
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(replace-regexp-in-string "/&quo= t; (regexp-quote "\\")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0(replace-regexp-in-string "c\\\\" &quo= t;c"
=C2=A0 =C2=A0 (org-babel-process-file-name out-file))))))=


Johan

=
--000000000000f34a2805a085d416--