From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?Q?Alain_Cl=C3=A9ment?= Subject: Re: Babel sql code block issue and patch proposal Date: Mon, 7 Mar 2011 10:15:28 +0100 Message-ID: References: <87sjv4pcwf.fsf@gmail.com> <8762s0kmoc.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001636499287f9b6fa049de0f2a9 Return-path: Received: from [140.186.70.92] (port=47343 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PwWax-0007ff-8J for emacs-orgmode@gnu.org; Mon, 07 Mar 2011 04:19:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PwWYE-0005f8-KG for emacs-orgmode@gnu.org; Mon, 07 Mar 2011 04:16:28 -0500 Received: from mailc1.unil.ch ([130.223.27.61]:55529) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PwWYE-0005e3-5F for emacs-orgmode@gnu.org; Mon, 07 Mar 2011 04:16:26 -0500 Received: from mail-bw0-f41.google.com ([209.85.214.41]) by mailc1.unil.ch stage1 with esmtpsa (Exim MailCleaner) id 1PwWYA-0007dl-Iy for from ; Mon, 07 Mar 2011 10:16:22 +0100 Received: by bwz17 with SMTP id 17so4165806bwz.0 for ; Mon, 07 Mar 2011 01:16:21 -0800 (PST) In-Reply-To: <8762s0kmoc.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eric Schulte Cc: emacs-orgmode@gnu.org --001636499287f9b6fa049de0f2a9 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Eric, Thanks for your message and sorry for the delay. Actually, escaping characters with backslashes is the problem within mysql when the =3DSOURCE=3D command is invoqued. To believe the forums, it seems = that this difficulty is well known among mysql users. The suggested solution there consists in piping the file content via the standard input of the mysql command instead of making use of the =3DSOURCE=3D command. In other w= ords, let the shell do the job of finding the file as mysql can't. My initial suggestion for a patch relies on this conclusion and seems to work well. No= w it's time to stop my own advertising and ask you about the cons of such a patch. Best regards and thank you again. - Alain 2011/3/3 Eric Schulte > Hi Alain, > > Would the following work (escaping "-"s with a backslash)? > > #+begin_src diff > diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el > index 364070e..838f013 100644 > --- a/lisp/ob-sql.el > +++ b/lisp/ob-sql.el > @@ -73,7 +73,9 @@ This function is called by > `org-babel-execute-src-block'." > (org-babel-process-file-name > out-file))) > ('mysql (format "mysql %s -e \"source %s\" > %s" > (or cmdline "") > - (org-babel-process-file-name in-file) > + (replace-regexp-in-string > + "\\-" "\\\\-" > + (org-babel-process-file-name in-file)= ) > (org-babel-process-file-name > out-file))) > ('postgresql (format > "psql -A -P footer=3Doff -F \"\t\" -f= %s > -o %s %s" > #+end_src > > Best -- Eric > > Alain Cl=C3=A9ment writes: > > > Hi Eric, > > > > Thanks for your prompt answer! Actually, it doesn't work since mysql > interprets backslashes as options, even between quotes. The value of my > > `org-babel-temporary-directory' is > "/var/folders/9E/9EMu+g0oHBSrq-h9sX6i1U+++TM/-Tmp-/babel-86766893", but > "+"'s are escaped with a backslash at some stage. > > > > Thanks, > > - Alain > > > > 2011/3/3 Eric Schulte > > > > Hi Alain, > > > > Does the following alternative fix work for you? > > > > #+begin_src diff
> > Changes in HEAD
> > Modified lisp/ob-sql.el
> > diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
> > index 364070e..604d444 100644
> > --- a/lisp/ob-sql.el
> > +++ b/lisp/ob-sql.el
> > @@ -71,7 +71,7 @@ This function is called by > `org-babel-execute-src-block'."
> > (or cmdline "")
> > (org-babel-process-file-name in-file)
> > (org-babel-process-file-name out-file)))
> > - ('mysql (format "mysql %s -e \"source %s\&quo= t; > > %s"
> > + ('mysql (format "mysql %s -e 'source %s' > > %s"
> > (or cmdline "")
> > (org-babel-process-file-name in-file)
> > (org-babel-process-file-name out-file)))
> > #+end_src
> > Also, just out of curiosity would you mind sharing an example result of > > `org-babel-temporary-directory' which contains backslashes? > > > > Thanks -- Eric > > > > Alain Cl?ment writes: > > > >> Hi everyone, > >> > >> The =3Dorg-babel-temp-file=3D string seems to be escaped with backslas= hes on > >> some platforms (like MacOSX), which is not very appreciated by the > =3Dmysql > >> -e=3D command. I suggest the following patch for =3Dob-sql.el=3D (Org-= mode > Version > >> 7.4 (release_7.4.590.g85d4d)): > >> > >> 74c74 > >> < ? ? ? ? ? ? ? ? ? ? ('mysql (format "mysql %s < %s > %s" > >> --- > >>> ? ? ? ? ? ? ? ? ? ? ('mysql (format "mysql %s -e \"source %s\" > %s" > >> > >> Best regards, > >> -- Alain > >> > >> -- > >> > >> > >> > >> Alain Cl?ment > >> Dr ?s sc. math?matiques > >> > >> Universit? de Lausanne > >> Quartier UNIL-Centre > >> B?timent Unicentre > >> Bureau 339 > >> CH-1015 Lausanne > >> > >> T. +41 21 692 20 36 (direct) > >> T. +41 21 692 20 60 (secr?tariat) > >> > >> alain.clement@unil.ch > > > > -- > > > > [lo_unil05_bleu] > > > > Alain Cl?ment > > Dr ?s sc. math?matiques > > > > Universit? de Lausanne > > Quartier UNIL-Centre > > B?timent Unicentre > > Bureau 339 > > CH-1015 Lausanne > > > > T. +41 21 692 20 36 (direct) > > T. +41 21 692 20 60 (secr?tariat) > > > > alain.clement@unil.ch > --=20 Alain Cl=C3=A9ment Dr =C3=A8s sc. math=C3=A9matiques Universit=C3=A9 de Lausanne Quartier UNIL-Centre B=C3=A2timent Unicentre Bureau 339 CH-1015 Lausanne T. +41 21 692 20 36 (direct) T. +41 21 692 20 60 (secr=C3=A9tariat) alain.clement@unil.ch --001636499287f9b6fa049de0f2a9 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Eric,
Thanks for your message and sorry for the dela= y.
Actually, escaping characters with backslashes is the problem = within mysql when the =3DSOURCE=3D command is invoqued. To believe the foru= ms, it seems that this difficulty is well known among mysql users. The sugg= ested solution there consists in piping the file content via the standard i= nput of the mysql command instead of making use of the =3DSOURCE=3D command= . In other words, let the shell do the job of finding the file as mysql can= 't. My initial suggestion for a patch relies on this conclusion and see= ms to work well. Now it's time to stop my own advertising and ask you a= bout the cons of such a patch.
Best regards and thank you again.
- Alain

2011/3/3 Eric Schulte <schulte.eric@gmai= l.com>
Hi Alain,

Would the following work (escaping "-"s with a backslash)?

#+begin_src diff
=C2=A0diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
=C2=A0index 364070e..838f013 100644
=C2=A0--- a/lisp/ob-sql.el
=C2=A0+++ b/lisp/ob-sql.el
=C2=A0@@ -73,7 +73,9 @@ This function is called by `org-babel-execut= e-src-block'."
=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(org-= babel-process-file-name out-file)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 ('mysql (format "mysql %s -e \"source %s\" > %s&q= uot;
=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 (or cmdline &qu= ot;")
=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 (org-babel-process-file-name = in-file)
=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-str= ing
=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 =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))
=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(org-babel-p= rocess-file-name out-file)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0('postgresql (format
=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"psql -A -P footer= =3Doff -F \"\t\" =C2=A0-f %s -o %s %s"
#+end_src

Best -- Eric

Alain Cl=C3=A9ment <alain.clement@unil.ch> writes:

> Hi Eric,
>
> Thanks for your prompt answer! Actually, it doesn't work since mys= ql interprets backslashes as options, even between quotes. The value of my<= br> > `org-babel-temporary-directory' is "/var/folders/9E/9EMu+g0oH= BSrq-h9sX6i1U+++TM/-Tmp-/babel-86766893", but "+"'s are = escaped with a backslash at some stage.
>
> Thanks,
> - Alain
>
> 2011/3/3 Eric Schulte <schulte.eric@gmail.com>
>
> =C2=A0 =C2=A0 Hi Alain,
>
> =C2=A0 =C2=A0 Does the following alternative fix work for you?
>
> #+begin_src diff<br>
> =C2=A0Changes in HEAD<br>
> =C2=A0 =C2=A0 =C2=A0Modified lisp/ob-sql.el<br>
> =C2=A0diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el<br>
> =C2=A0index 364070e..604d444 100644<br>
> =C2=A0--- a/lisp/ob-sql.el<br>
> =C2=A0+++ b/lisp/ob-sql.el<br>
> =C2=A0@@ -71,7 +71,7 @@ This function is called by `org-babel-execute-= src-block&#39;.&quot;<br>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = (or cmdline &quot;&quot;)<br>
> =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 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = (org-babel-process-file-name out-file)))<br>
> =C2=A0- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(&#39;mysql (format &= ;quot;mysql %s -e \&quot;source %s\&quot; &gt; %s&quot;<= br>
> =C2=A0+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(&#39;mysql (format &= ;quot;mysql %s -e &#39;source %s&#39; &gt; %s&quot;<br&g= t;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = (or cmdline &quot;&quot;)<br>
> =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 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(= org-babel-process-file-name out-file)))<br>
> #+end_src<br>
> Also, just out of curiosity would you mind sharing an example res= ult of
> `org-babel-temporary-directory' which contains backslashes?
>
> Thanks -- Eric
>
> Alain Cl?ment <alain.clement@unil.ch> writes:
>
>> Hi everyone,
>>
>> The =3Dorg-babel-temp-file=3D string seems to be escaped with back= slashes on
>> some platforms (like MacOSX), which is not very appreciated by the= =3Dmysql
>> -e=3D command. I suggest the following patch for =3Dob-sql.el=3D (= Org-mode Version
>> 7.4 (release_7.4.590.g85d4d)):
>>
>> 74c74
>> < ? ? ? ? ? ? ? ? ? ? ('mysql (format "mysql %s < %= s > %s"
>> ---
>>> ? ? ? ? ? ? ? ? ? ? ('mysql (format "mysql %s -e \&qu= ot;source %s\" > %s"
>>
>> Best regards,
>> -- Alain
>>
>> --
>>
>>
>>
>> Alain Cl?ment
>> Dr ?s sc. math?matiques
>>
>> Universit? de Lausanne
>> Quartier UNIL-Centre
>> B?timent Unicentre
>> Bureau 339
>> CH-1015 Lausanne
>>
>> T. +41 21 692 20 36 (direct)
>> T. +41 21 692 20 60 (secr?tariat)
>>
>> alain.c= lement@unil.ch
>
> --
>
> [lo_unil05_bleu]
>
> Alain Cl?ment
> Dr ?s sc. math?matiques
>
> Universit? de Lausanne
> Quartier UNIL-Centre
> B?timent Unicentre
> Bureau 339
> CH-1015 Lausanne
>
> T. +41 21 692 20 36 (direct)
> T. +41 21 692 20 60 (secr?tariat)
>
> alain.cleme= nt@unil.ch



--



Alain Cl=C3=A9me= nt
Dr =C3=A8s sc. math=C3=A9matiques

Universit=C3=A9 de Lausanne
Quartier UNIL-Centre
B=C3=A2timent Un= icentre
Bureau 339
CH-1015 Lausanne

T. +41 21 692 20 36 (direc= t)
T. +41 21 692 20 60 (secr=C3=A9tariat)

alain.clement@unil.ch
--001636499287f9b6fa049de0f2a9--