From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: Babel sql code block issue and patch proposal Date: Mon, 07 Mar 2011 08:33:22 -0700 Message-ID: <87sjuzeyil.fsf@gmail.com> References: <87sjv4pcwf.fsf@gmail.com> <8762s0kmoc.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=57257 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PwcRA-0006zs-JS for emacs-orgmode@gnu.org; Mon, 07 Mar 2011 10:33:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PwcR8-0003Ji-Co for emacs-orgmode@gnu.org; Mon, 07 Mar 2011 10:33:32 -0500 Received: from mail-pz0-f41.google.com ([209.85.210.41]:34911) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PwcR8-0003JS-0F for emacs-orgmode@gnu.org; Mon, 07 Mar 2011 10:33:30 -0500 Received: by pzk33 with SMTP id 33so1171429pzk.0 for ; Mon, 07 Mar 2011 07:33:29 -0800 (PST) In-Reply-To: ("Alain =?utf-8?Q?Cl=C3=A9ment=22's?= message of "Mon, 7 Mar 2011 10:15:28 +0100") 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: Alain =?utf-8?Q?Cl=C3=A9ment?= Cc: emacs-orgmode@gnu.org 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 mysq= l when the =3DSOURCE=3D command is invoqued. To believe the forums, it seem= s 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 mak= ing 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 an= d 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, >=20=20=20=20 > 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-sr= c-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?ment writes: > >> Hi Eric, >> >> Thanks for your prompt answer! Actually, it doesn't work since mysql int= erprets backslashes as options, even between quotes. The value of my >> `org-babel-temporary-directory' is "/var/folders/9E/9EMu+g0oHBSrq-h9sX6i= 1U+++TM/-Tmp-/babel-86766893", but "+"'s are escaped with a backslash at so= me 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-blo= ck'."
>> ? ? ? ? ? ? ? ? ? ? (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' &g= t; %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 backslash= es on >>> some platforms (like MacOSX), which is not very appreciated by the =3Dm= ysql >>> -e=3D command. I suggest the following patch for =3Dob-sql.el=3D (Org-m= ode 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]=20=20=20=20=20=20=20=20=20=20=20=20=20 > > 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