emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <schulte.eric@gmail.com>
To: Eric Abrahamsen <eric@ericabrahamsen.net>
Cc: emacs-orgmode@gnu.org
Subject: Re: Org-mode as a metalanguage: calling SQL "functions"
Date: Mon, 01 Apr 2013 19:45:29 -0600	[thread overview]
Message-ID: <87y5d1itxx.fsf@gmail.com> (raw)
In-Reply-To: 87vc85raoh.fsf@ericabrahamsen.net

[-- Attachment #1: Type: text/plain, Size: 1871 bytes --]

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Gary Oberbrunner <garyo@oberbrunner.com> writes:
>
>> 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?
>

Yes, your example should work.  From the "Evaluating code blocks"
section of the Org-mode manual.

,----
|    It is also possible to evaluate named code blocks from anywhere in an
| Org mode buffer or an Org mode table.  Live code blocks located in the
| current Org mode buffer or in the "Library of Babel" (see *note Library
| of Babel::) can be executed.  Named code blocks can be executed with a
| separate '#+CALL:' line or inline within a block of text.
`----

There is no need to load code blocks in the same buffer into the library
of babel.

This example works for me evaluating code blocks in the same buffer
using call lines.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: in-buffer-execution-example.org --]
[-- Type: text/x-org, Size: 364 bytes --]

#+Title: Call Example

#+name: example-block
#+begin_src sh :var input=""
  echo "input is $input"
#+end_src

Here's a simple call using a named argument.
#+call: example-block(input="foo")

#+RESULTS: example-block(input="foo")
: input is foo

It also works with a positional argument.
#+call: example-block("bar")

#+RESULTS: example-block("bar")
: input is bar

[-- Attachment #3: Type: text/plain, Size: 56 bytes --]


When I export this to e.g., html I get the following.


[-- Attachment #4: example.html --]
[-- Type: text/html, Size: 4008 bytes --]

[-- Attachment #5: Type: text/plain, Size: 214 bytes --]


The call lines are replaced with their results as part of the export
process.

If the above doesn't work for you, then I imagine something is wrong
with your install.

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

  reply	other threads:[~2013-04-02  1:49 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-01 19:28 Org-mode as a metalanguage: calling SQL "functions" Gary Oberbrunner
2013-04-01 20:41 ` Mike Gauland
2013-04-02  1:19 ` Eric Abrahamsen
2013-04-02  1:45   ` Eric Schulte [this message]
2013-04-02  2:46     ` Eric Abrahamsen
2013-04-02  2:54     ` Gary Oberbrunner
2013-04-02 21:54       ` Eric Schulte
2013-04-03  5:50         ` Andreas Röhler
2013-04-03  5:54         ` Carsten Dominik
2013-04-03 13:09           ` Eric Schulte
2013-04-04 12:26             ` Sebastien Vauban
2013-04-04 12:49               ` Eric Schulte
2013-04-04 20:10                 ` Sebastien Vauban
2013-04-05 15:43                   ` Gary Oberbrunner
2013-04-05 16:31                     ` Eric Schulte
2013-04-05 17:51                       ` Andreas Röhler
2013-04-06 20:44                       ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y5d1itxx.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=eric@ericabrahamsen.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).