From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: [babel] Is this supported? Date: Thu, 03 Dec 2009 10:52:03 -0500 Message-ID: <87y6lkukbg.fsf@stats.ox.ac.uk> References: <87ws141evl.fsf@mundaneum.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NGDyY-0003G4-1u for emacs-orgmode@gnu.org; Thu, 03 Dec 2009 10:52:14 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NGDyT-0003FN-Ga for emacs-orgmode@gnu.org; Thu, 03 Dec 2009 10:52:13 -0500 Received: from [199.232.76.173] (port=46593 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NGDyT-0003FK-9c for emacs-orgmode@gnu.org; Thu, 03 Dec 2009 10:52:09 -0500 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:65244) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NGDyS-0003vf-P7 for emacs-orgmode@gnu.org; Thu, 03 Dec 2009 10:52:09 -0500 Received: from blackcap.stats.ox.ac.uk (blackcap.stats [163.1.210.5]) by markov.stats.ox.ac.uk (8.13.6/8.13.6) with ESMTP id nB3Fq6L8003578 for ; Thu, 3 Dec 2009 15:52:06 GMT In-Reply-To: <87ws141evl.fsf@mundaneum.com> (=?utf-8?Q?=22S=C3=A9bastien?= Vauban"'s message of "Thu, 03 Dec 2009 12:22:22 +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: emacs-orgmode@gnu.org S=C3=A9bastien Vauban writes: <...> > Is there a way to tangle it with some string replacements being made, suc= h as: > > | pTable | dossier | > | pColumn | pfiNew | > | pDatatype | string | > | pAcceptnullvalues | NULL | > > I've tried the following, with no success: > > #+srcname: add-column-in-table(pTable=3Ddossier,pColumn=3DpfiNew,pDatatyp= e=3Dstring,pAcceptnullvalues=3DNULL) Hi Seb, Those function-arguments / variable assignments won't affect the *tangled* output. Afaik the only method for making substitutions in the tangled output is the <> block references. So one way to achieve what you want would be to create a block for each string replacement (Example [1] below; I don't know if I've got the quoting right in the sql output). But perhaps Tom/Eric will have a better answer. Incidentally, it seems that we do not currently support variables when *evaluating* an sql block. I.e. the function-arguments that you used: > #+srcname: add-column-in-table(pTable=3Ddossier,pColumn=3DpfiNew,pDatatyp= e=3Dstring,pAcceptnullvalues=3DNULL) will have no effect. The patch below[2] implements that. I'll let Eric decide whether it's appropriate as I don't know anything about sql. Note that you would need to quote the strings in your srcname line (i.e. (pTable=3D"dossier", ...)) Dan > #+begin_src sql :tangle dossier.sql > -- add column `pfiDossierSentToSecteur' (if column does not exist= yet) > IF NOT EXISTS (SELECT * > FROM INFORMATION_SCHEMA.COLUMNS > WHERE TABLE_NAME =3D 'pTable' > AND COLUMN_NAME =3D 'pColumn) > BEGIN > ALTER TABLE pTable > ADD pColumn pDatatype pAcceptnullvalues > END > GO > #+end_src > > Is such a feature supported, or another way to come down to the same resu= lt? Footnotes: [1]=20 ---------------------------------------------------------------- #+srcname: pTable #+begin_src emacs-lisp "dossier" #+end_src #+srcname: pColumn #+begin_src emacs-lisp "pfiNew" #+end_src #+srcname: pDatatype #+begin_src emacs-lisp "string" #+end_src #+srcname: pAcceptnullvalues #+begin_src emacs-lisp "NULL" #+end_src #+begin_src sql :tangle dossier.sql :engine mysql -- add column `pfiDossierSentToSecteur' (if column does not exist y= et) IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME =3D <> AND COLUMN_NAME =3D <>) BEGIN ALTER TABLE <> ADD <> <> <> END GO #+end_src ---------------------------------------------------------------- [2]=20 ---------------------------------------------------------------- diff --git a/contrib/babel/lisp/langs/org-babel-sql.el b/contrib/babel/lisp= /langs/org-babel-sql.el index 837c5fd..7e37fee 100644 --- a/contrib/babel/lisp/langs/org-babel-sql.el +++ b/contrib/babel/lisp/langs/org-babel-sql.el @@ -55,7 +55,8 @@ "Execute a block of Sql code with org-babel. This function is called by `org-babel-execute-src-block'." (message "executing Sql source code block") - (let* ((result-params (split-string (or (cdr (assoc :results params)) ""= ))) + (let* ((processed-params (org-babel-process-params params)) + (vars (second processed-params)) (cmdline (cdr (assoc :cmdline params))) (engine (cdr (assoc :engine params))) (in-file (make-temp-file "org-babel-sql-in")) @@ -66,6 +67,9 @@ called by `org-babel-execute-src-block'." (or cmdline "") in-file out-file)) ('nil (error "sql engine not specified")) (t (error "no support for the %s sql engine" engine)))= )) + (mapc (lambda (pair) + (setq body (replace-regexp-in-string (format "%s" (car pair)) (= cdr pair) body))) + vars) (with-temp-file in-file (insert body)) (message command) (shell-command command) ----------------------------------------------------------------