From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gary Oberbrunner Subject: Org-mode as a metalanguage: calling SQL "functions" Date: Mon, 1 Apr 2013 15:28:13 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b339dbb361f4904d9519f66 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:57345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMkOu-0003uF-Da for emacs-orgmode@gnu.org; Mon, 01 Apr 2013 15:28:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMkOs-0001E6-C5 for emacs-orgmode@gnu.org; Mon, 01 Apr 2013 15:28:16 -0400 Received: from mail-oa0-f49.google.com ([209.85.219.49]:50160) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMkOs-0001Dt-81 for emacs-orgmode@gnu.org; Mon, 01 Apr 2013 15:28:14 -0400 Received: by mail-oa0-f49.google.com with SMTP id j6so2319425oag.36 for ; Mon, 01 Apr 2013 12:28:13 -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.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Orgmode Mailing List --047d7b339dbb361f4904d9519f66 Content-Type: text/plain; charset=ISO-8859-1 It seems like you can define "procedures" in org-mode and call them from elsewhere, with args. But I'm not sure how well-defined that process is; the documentation is not completely perfect yet I think. Here's one thing I'm trying that seems not to work. I define a "procedure" as a named ref called recorddate with two args, ver and order. The idea is I could later call that with different values of those args. #+NAME: recorddate(order="desc") #+BEGIN_SRC sql :exports none :colnames no :results scalar select Event.CreatedAt from Event join MachineInfo as MI on Event.MachineInfoId=MI.Id where Event.CreatedAt is not NULL order by CreatedAt $order limit 1; #+END_SRC sql (BTW, I really like how $ vars are substituted into SQL. Nice.) But when I try to call it like this: * earliest record is call_recorddate(ver="'.'", order="asc") or like this: #+CALL: recorddate(ver="'.'", order="asc") and I try to export as LaTeX (or anything), I get org-babel-ref-resolve: Reference 'recorddate' not found in this buffer Is this supposed to work? -- Gary --047d7b339dbb361f4904d9519f66 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
It seems like you can define "procedures" in org= -mode and call them from elsewhere, with args.
But I'm not su= re how well-defined that process is; the documentation is not completely pe= rfect yet I think. =A0Here's one thing I'm trying that seems not to= work.

I define a "procedure" as a named= ref called recorddate with two args, ver and order. =A0The idea is I could= later call that with different values of those args.

#+NAME: recorddate(order=3D"desc")
#+BEGIN_SRC sql :exports none :colnames no :results scalar
sele= ct Event.CreatedAt from Event join MachineInfo as MI on Event.MachineInfoId= =3DMI.Id
=A0where Event.CreatedAt is not NULL order by CreatedAt $order limit 1= ;
#+END_SRC sql

(BTW, I= really like how $ vars are substituted into SQL. =A0Nice.) =A0But when I t= ry to call it like this:

=A0* earliest record is=A0call_recorddate(v= er=3D"'.'", order=3D"asc")
or l= ike this:
=A0#+CALL: recorddate(ver=3D"'.'&quo= t;, order=3D"asc")

and I try to export as LaTeX (or anything),= I get=A0
=A0org-babel-ref-resolve: Reference 'recordda= te' not found in this buffer

Is th= is supposed to work?

--
Gary
--047d7b339dbb361f4904d9519f66--