emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: dmg <dmg@turingmachine.org>
To: "Thomas S. Dye" <tsd@tsdye.com>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: how to update and add info to babel documentation?
Date: Tue, 19 Jul 2016 13:49:41 -0700	[thread overview]
Message-ID: <CAEBXXD9Aa6Tc3Wzzm+OaGxSJDY3scstToDvV7aMpYNH6k9hbKQ@mail.gmail.com> (raw)
In-Reply-To: <m2mvldsgmp.fsf@tsdye.com>


[-- Attachment #1.1: Type: text/plain, Size: 1039 bytes --]

Thanks Tom,

Here is my patch.


On Tue, Jul 19, 2016 at 10:05 AM, Thomas S. Dye <tsd@tsdye.com> wrote:

> Aloha dmg,
>
> You can find instructions here:
>
> http://orgmode.org/worg/worg-git.html
>
> Thanks for your help.
>
> All the best,
> Tom
>
> dmg writes:
>
> > hi there,
> >
> > I was trying to find the sources for the babel language documentation.
> > Specifically:
> >
> >
> > http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-sqlite.html
> >
> > Could anybody please tell me which is the best way to submit a patch to
> it?
> >
> > Specifically, I would like to document the use of variables in the mode.
> I had
> > to read its source code to know that you can to prefix the variable name
> with
> > $ for it to work, eg:
> >
> >
> > #+BEGIN_SRC sqlite :db /tmp/rip.db :var x="table"
> > select * from $x;
> > #+END_SRC
> >
> >
> > ​thank you,​
>
>
> --
> Thomas S. Dye
> http://www.tsdye.com
>



-- 
--dmg

---
Daniel M. German
http://turingmachine.org

[-- Attachment #1.2: Type: text/html, Size: 2394 bytes --]

[-- Attachment #2: 0001-added-documentation-on-how-ot-pass-variables-to-sqli.patch --]
[-- Type: text/x-patch, Size: 2715 bytes --]

From 67f1d69ea3de516fd46ce8bc74d0b11f3d06cdc4 Mon Sep 17 00:00:00 2001
From: D German <dmg@uvic.ca>
Date: Tue, 19 Jul 2016 13:47:14 -0700
Subject: [PATCH] added documentation on how ot pass variables to sqlite

---
 org-contrib/babel/languages/ob-doc-sqlite.org | 60 +++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/org-contrib/babel/languages/ob-doc-sqlite.org b/org-contrib/babel/languages/ob-doc-sqlite.org
index 6b5be03..04deb57 100644
--- a/org-contrib/babel/languages/ob-doc-sqlite.org
+++ b/org-contrib/babel/languages/ob-doc-sqlite.org
@@ -112,6 +112,18 @@ There are 11 SQLite-specific header arguments.
                 =.import=. 
  - nullvalue :: a string to use in place of NULL values.
 
+*** Variables 
+
+It is possible to pass variables to sqlite. Variables can be of type table or scalar. Variables are defined using :var=<value>
+and referred in the code block as $<name>.
+
+ - Table variables :: Table variables are exported as a temporary csv file that
+    can then be imported by sqlite. The actual value of the variable is the name of temporary csv file. 
+
+ - Scalar variables :: This is a value that will replace references
+       to variable's name. String variables should be quoted;
+       otherwise they are considered a table variable.
+    
 
 ** Sessions
 SQLite sessions are not supported.
@@ -152,4 +164,52 @@ Hello world!
 Note that =db= and =dir= together specify the path to the file
 that holds the SQLite database.
 
+** Using scalar variables
+
+In this example we create a variable with the name of the relation to query and a value to use in a query where clause.
+Note that the replacement excludes the quotes of string variables.
+
+#+BEGIN_EXAMPLE
+,#+BEGIN_SRC sqlite :db /tmp/rip.db :var rel="tname" n=300 :colnames yes
+drop table if exists $rel;
+create table $rel(n int, id int);
+insert into $rel(n,id) values (1,210), (3,800);
+select * from $rel where id > $n;
+,#+END_SRC
+
+,#+RESULTS:
+| 3 | 800 |
+#+END_EXAMPLE
+
+** Using table variables
+
+We can also pass a table to a query. In this case, the contents of the table are exported as a csv file that can then 
+be imported into a relation:
+
+#+BEGIN_EXAMPLE
+,#+NAME: tableexample
+| id |  n |
+|----+----|
+|  1 |  5 |
+|  2 |  9 |
+|  3 | 10 |
+|  4 |  9 |
+|  5 | 10 |
+
+,#+begin_src sqlite :db /tmp/rip.db :var orgtable=tableexample :colnames yes
+drop table if exists testtable;
+create table testtable(id int, n int);
+.mode csv testtable
+.import $orgtable testtable
+select n, count(*) from testtable group by n;
+,#+end_src
+
+,#+RESULTS:
+|  n | count(*) |
+|----+----------|
+|  5 |        1 |
+|  9 |        2 |
+| 10 |        2 |
+#+END_EXAMPLE
+
 
-- 
2.7.4


  reply	other threads:[~2016-07-19 20:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-19  2:46 how to update and add info to babel documentation? dmg
2016-07-19 17:05 ` Thomas S. Dye
2016-07-19 20:49   ` dmg [this message]
2016-07-20 17:07     ` Thomas S. Dye

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=CAEBXXD9Aa6Tc3Wzzm+OaGxSJDY3scstToDvV7aMpYNH6k9hbKQ@mail.gmail.com \
    --to=dmg@turingmachine.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=tsd@tsdye.com \
    /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).