* how to update and add info to babel documentation?
@ 2016-07-19 2:46 dmg
2016-07-19 17:05 ` Thomas S. Dye
0 siblings, 1 reply; 4+ messages in thread
From: dmg @ 2016-07-19 2:46 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 612 bytes --]
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,
--
--dmg
---
Daniel M. German
http://turingmachine.org
[-- Attachment #2: Type: text/html, Size: 2428 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: how to update and add info to babel documentation?
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
0 siblings, 1 reply; 4+ messages in thread
From: Thomas S. Dye @ 2016-07-19 17:05 UTC (permalink / raw)
To: dmg; +Cc: emacs-orgmode
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: how to update and add info to babel documentation?
2016-07-19 17:05 ` Thomas S. Dye
@ 2016-07-19 20:49 ` dmg
2016-07-20 17:07 ` Thomas S. Dye
0 siblings, 1 reply; 4+ messages in thread
From: dmg @ 2016-07-19 20:49 UTC (permalink / raw)
To: Thomas S. Dye; +Cc: emacs-orgmode
[-- 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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: how to update and add info to babel documentation?
2016-07-19 20:49 ` dmg
@ 2016-07-20 17:07 ` Thomas S. Dye
0 siblings, 0 replies; 4+ messages in thread
From: Thomas S. Dye @ 2016-07-20 17:07 UTC (permalink / raw)
To: dmg; +Cc: emacs-orgmode
Aloha Daniel,
Please feel free to push your changes directly to Worg.
Thanks again for your help.
All the best,
Tom
dmg writes:
> 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
--
Thomas S. Dye
http://www.tsdye.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-07-20 17:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2016-07-20 17:07 ` Thomas S. Dye
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).