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 17:24:05 +0100 Message-ID: References: <87sjv4pcwf.fsf@gmail.com> <8762s0kmoc.fsf@gmail.com> <87sjuzeyil.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=0016e64805aed72926049de6ed7c Return-path: Received: from [140.186.70.92] (port=49840 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PwdEV-0006Co-Pk for emacs-orgmode@gnu.org; Mon, 07 Mar 2011 11:24:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PwdET-0006Un-JW for emacs-orgmode@gnu.org; Mon, 07 Mar 2011 11:24:31 -0500 Received: from mailc1.unil.ch ([130.223.27.61]:54927) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PwdET-0006U8-5b for emacs-orgmode@gnu.org; Mon, 07 Mar 2011 11:24:29 -0500 Received: from mail-ew0-f41.google.com ([209.85.215.41]) by mailc1.unil.ch stage1 with esmtpsa (Exim MailCleaner) id 1PwdER-0002lB-8Z for from ; Mon, 07 Mar 2011 17:24:27 +0100 Received: by ewy10 with SMTP id 10so1546595ewy.0 for ; Mon, 07 Mar 2011 08:24:25 -0800 (PST) In-Reply-To: <87sjuzeyil.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 --0016e64805aed72926049de6ed7c Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Eric, Thank you so much, your "fearless development" is great and very appreciated! Best regards, - Alain 2011/3/7 Eric Schulte > To be honest, I don't have any overly motivating reasons for passing the > file name to mysql rather than piping the contents of the file. Aside > from consistency with the other SQL engines, the nagging feeling that > things are the way they are for a reason, and a healthy fear of the new > and unknown. However development is not for cowards, I've applied your > suggestion, and mysql is now reading input through stdin. > > Best -- Eric > > Alain Cl=C3=A9ment writes: > > > 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, i= t seems > that this difficulty is well > > known among mysql users. The suggested solution there consists in pipin= g > the file content via the standard input 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 a= s > mysql can't. My initial suggestion for a patch relies on this conclusion = and > seems to work well. Now > > 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\&quo= t; > > %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?ment 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\" > %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 o= f > >> `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 backsla= shes > 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 > > > > -- > > > > [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 --0016e64805aed72926049de6ed7c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Eric,
Thank you so much, your "fearless develop= ment" is great and very appreciated!
Best regards,
- Alain

2011/3/7 Eric Schul= te <schulte.= eric@gmail.com>
To be honest, I don't have any overly m= otivating reasons for passing the
file name to mysql rather than piping the contents of the file. =C2=A0Aside=
from consistency with the other SQL engines, the nagging feeling that
things are the way they are for a reason, and a healthy fear of the new
and unknown. =C2=A0However development is not for cowards, I've applied= your
suggestion, and mysql is now reading input through stdin.

Best -- Eric

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

> Hi Eric,
> Thanks for your message and sorry for the dela= y.
> Actually, escaping characters with backslashes is the problem within m= ysql when the =3DSOURCE=3D command is invoqued. To believe the forums, it s= eems that this difficulty is well
> known among mysql users. The suggested solution there consists in pipi= ng the file content via the standard input 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 conclu= sion and seems to work well. Now
> 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 <sc= hulte.eric@gmail.com>
>
> =C2=A0 =C2=A0 Hi Alain,
>
> =C2=A0 =C2=A0 Would the following work (escaping "-"s with a= backslash)?
>
> #+begin_src diff<br>
> <div> diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el<br>
> </div> index 364070e..838f013 100644<br>
> <div> --- a/lisp/ob-sql.el<br>
> =C2=A0+++ b/lisp/ob-sql.el<br>
> </div> @@ -73,7 +73,9 @@ This function is called by `org-b= abel-execute-src-block&#39;.&quot;<br>
> <div> =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 =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 (org-b= abel-process-file-name in-file)<br>
> </div> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (replace-regexp-in-string<br>
> =C2=A0+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &q= uot;\\-&quot; &quot;\\\\-&quot;<br>
> =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>
> <div> =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>
> </div> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (&#39;postgresql (= format<br>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &qu= ot;psql -A -P footer=3Doff -F \&quot;\t\&quot; -f %s -o %s %s&q= uot;<br>
> #+end_src<br>
> Best -- Eric
>
> Alain Cl?ment <alain.cleme= nt@unil.ch> 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 <schulte.eric@gmail.com>
>>
>> ? ? Hi Alain,
>>
>> ? ? Does the following alternative fix work for you?
>>
>> #+begin_src diff<br>
>> ?Changes in HEAD<br>
>> ? ? ?Modified lisp/ob-sql.el<br>
>> ?diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el<br>
>> ?index 364070e..604d444 100644<br>
>> ?--- a/lisp/ob-sql.el<br>
>> ?+++ b/lisp/ob-sql.el<br>
>> ?@@ -71,7 +71,7 @@ This function is called by `org-babel-execute-s= rc-block&#39;.&quot;<br>
>> ? ? ? ? ? ? ? ? ? ? (or cmdline &quot;&quot;)<br> >> ? ? ? ? ? ? ? ? ? ? (org-babel-process-file-name in-file)<br>= ;
>> ? ? ? ? ? ? ? ? ? ? (org-babel-process-file-name out-file)))<br= >
>> ?- ? ? ? ? ?(&#39;mysql (format &quot;mysql %s -e \&qu= ot;source %s\&quot; &gt; %s&quot;<br>
>> ?+ ? ? ? ? ?(&#39;mysql (format &quot;mysql %s -e &#39= ;source %s&#39; &gt; %s&quot;<br>
>> ? ? ? ? ? ? ? ? ? ? (or cmdline &quot;&quot;)<br> >> ? ? ? ? ? ? ? ? ? ?(org-babel-process-file-name in-file)<br>=
>> ? ? ? ? ? ? ? ? ? ?(org-babel-process-file-name out-file)))<br&= gt;
>> #+end_src<br>
>> Also, just out of curiosity would you mind sharing an example resu= lt of
>> `org-babel-temporary-directory' which contains backslashes? >>
>> Thanks -- Eric
>>
>> Alain Cl?ment <alain.c= lement@unil.ch> writes:
>>
>>> Hi everyone,
>>>
>>> The =3Dorg-babel-temp-file=3D string seems to be escaped with = backslashes 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 &l= t; %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=
>
> --
>
> [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



--



Alai= n Cl=C3=A9ment
Dr =C3=A8s sc. math=C3=A9matiques

Universit=C3=A9 de Lausanne
Qua= rtier UNIL-Centre
B=C3=A2timent Unicentre
Bureau 339
CH-1015 Lausa= nne

T. +41 21 692 20 36 (direct)
T. +41 21 692 20 60 (secr=C3=A9t= ariat)

al= ain.clement@unil.ch
--0016e64805aed72926049de6ed7c--