Re: Add 'readonly' option to ob-sqlite

2024-06-23 Thread dmg
  (list  . :any)
 (separator . :any)
-(nullvalue . :any))
+(nullvalue . :any)
+(readonly-p . :any))
   "Sqlite specific header args.")
 
 (defun org-babel-expand-body:sqlite (body params)
@@ -76,7 +77,8 @@ This function is called by `org-babel-execute-src-block'."
 	(db (cdr (assq :db params)))
 	(separator (cdr (assq :separator params)))
 	(nullvalue (cdr (assq :nullvalue params)))
-	(headers-p (equal "yes" (cdr (assq :colnames params
+(headers-p (equal "yes" (cdr (assq :colnames params
+(readonly-p (equal "yes" (cdr (assq :readonly params
 	(others (delq nil (mapcar
 			   (lambda (arg) (car (assq arg params)))
 			   (list :header :echo :bail :column
@@ -85,7 +87,7 @@ This function is called by `org-babel-execute-src-block'."
   (insert
(org-babel-eval
 	(org-fill-template
-	 "%cmd %header %separator %nullvalue %others %csv %db "
+	 "%cmd %header %separator %nullvalue %others %csv %readonly %db "
 	 (list
 	  (cons "cmd" org-babel-sqlite3-command)
 	  (cons "header" (if headers-p "-header" "-noheader"))
@@ -103,6 +105,8 @@ This function is called by `org-babel-execute-src-block'."
 			  (member :html others) separator)
 			  ""
 			"-csv"))
+	  (cons "readonly"
+		(if readonly-p "-readonly" ""))
   (cons "db" (or db ""
 	;; body of the code block
 	(org-babel-expand-body:sqlite body params)))
-- 
2.45.2






--
Daniel M. German  ""Geek" is a badge of honor."
Eric Schmidt, CEO of Novell
http://turingmachine.org/
http://silvernegative.com/
dmg (at) uvic (dot) ca
replace (at) with @ and (dot) with .



bug processing non emacs-lisp blocks

2021-07-28 Thread dmg
org-babel-load-file will try to tangle any source block that contains
the substring emacs-lisp or elisp in their language.

For example, the following code block will be tangled:

#+begin_src emacs-lispDONOT
(use-package "org-sidebar")
#+end_src

the following patch fixes that problem. The Regular expression should
be more stringent, so it does match exactly the string and not a
substring.

I think this is a regression. I used to comment out blocks from my
.org init files by simply adding a XXX (as in emacs-lisp). In
current org these blocks are tangled :(



-- 
--dmg

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


patch
Description: Binary data


[O] patch to worg: documenting perl support in babel blocks

2018-06-27 Thread dmg
hi everybody,

I have a patch to contribute to the website. I have an account in the
git repo, but I cannot push.


I am attaching the patch.

thank you,



-- 
--dmg

---
D M German
http://turingmachine.org
From f265fe36a1633dc9b43c98a93eabcb31607939e5 Mon Sep 17 00:00:00 2001
From: D German 
Date: Wed, 27 Jun 2018 18:13:53 -0700
Subject: [PATCH] First crack at documenting perl in Babel blocks

* org-contrib/babel/languages/ob-doc-perl.org: Document perl in Babel

Created the file and documented how to use perl in Babel blocks,
Including how to pass parameters to the block and how to return
values (including tables).
---
 org-contrib/babel/languages/ob-doc-perl.org | 261 
 1 file changed, 261 insertions(+)
 create mode 100644 org-contrib/babel/languages/ob-doc-perl.org

diff --git a/org-contrib/babel/languages/ob-doc-perl.org b/org-contrib/babel/languages/ob-doc-perl.org
new file mode 100644
index ..52524c43
--- /dev/null
+++ b/org-contrib/babel/languages/ob-doc-perl.org
@@ -0,0 +1,261 @@
+#+OPTIONS:H:3 num:nil toc:2 \n:nil ::t |:t ^:{} -:t f:t *:t tex:t d:(HIDE) tags:not-in-toc
+#+STARTUP:align fold nodlcheck hidestars oddeven lognotestate hideblocks
+#+SEQ_TODO:   TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
+#+TAGS:   Write(w) Update(u) Fix(f) Check(c) noexport(n)
+#+TITLE:  Perl in Org Mode
+#+AUTHOR: Daniel M. German
+#+EMAIL:  dmg[at]uvic[dot]ca
+#+LANGUAGE:   en
+#+HTML_HEAD:  #outline-container-introduction{ clear:both; }
+#+LINK_UP:../languages.html
+#+LINK_HOME:  https://orgmode.org/worg/
+#+EXCLUDE_TAGS: noexport
+
+#+name: banner
+#+begin_export html
+  
+  
+  Org Mode support for http://www.perl.org/";>Perl
+  
+  
+  http://www.perl.org/";>
+  
+  
+  
+  
+#+end_export
+
+* Template Checklist [11/12]   :noexport:
+  - [X] Revise #+TITLE:
+  - [X] Indicate #+AUTHOR:
+  - [X] Add #+EMAIL:
+  - [X] Revise banner source block [3/3]
+- [X] Add link to a useful language web site
+- [X] Replace "Language" with language name
+- [X] Find a suitable graphic and use it to link to the language
+  web site
+  - [X] Write an [[Introduction]]
+  - [X] Describe [[Requirements%20and%20Setup][Requirements and Setup]]
+  - [X] Replace "Language" with language name in [[Org%20Mode%20Features%20for%20Language%20Source%20Code%20Blocks][Org Mode Features for Language Source Code Blocks]]
+  - [X] Describe [[Header%20Arguments][Header Arguments]]
+  - [X] Describe support for [[Sessions]]
+  - [X] Describe [[Result%20Types][Result Types]]
+  - [ ] Describe [[Other]] differences from supported languages
+  - [X] Provide brief [[Examples%20of%20Use][Examples of Use]]
+* Introduction
+
+This document is a short introduction to using perl within org-mode. 
+
+
+* Requirements and Setup
+
+The only requirement is installed in the computer where org babel is executing the scripts.
+
+
+#+begin_src emacs-lisp :exports code
+  (org-babel-do-load-languages
+   'org-babel-load-languages
+   '((lisp . t)))
+#+end_src
+
+* Org Mode Features for Perl Code Blocks
+** Header Arguments
+
+The support of perl in Babel is basic. There 
+There are no language-specific arguments for perl code blocks.
+
+** Result Types
+
+The only supported type is ~value~
+
+** Support for sessions
+
+There is no support for sessions.
+
+** var
+
+It is possible ot pass several variables to perl, including table variables. See below.
+
+* Examples of Use
+
+These are two simple examples:
+
+#+BEGIN_EXAMPLE
+#+BEGIN_SRC perl :results value
+"hello world";
+#+END_SRC
+
+#+RESULTS:
+: hello world
+#+END_EXAMPLE
+
+#+begin_src perl 
+10 * 20 + 5;
+#+end_src
+
+#+RESULTS:
+: 205
+#+end_example
+
+#+RESULTS: countingTo10
+
+* Other types of output
+
+Perl scripts might generate data that is parsed by Org. Unfortunately
+its current support is not very powerful. Currently there is only one method to receive data: ~:results value~. This is the default.
+The result of the code block (the value of the last expression evaluated) if returned to org. If the result is an array (up to two dimensions)
+it is interpreted as a table. Some examples below:
+
+
+#+BEGIN_EXAMPLE
+#+BEGIN_SRC perl :results value
+[[1,2],[2,4]]
+#+END_SRC
+
+#+RESULTS:
+| 1 | 2 |
+| 2 | 4 |
+#+END_EXAMPLE
+
+#+BEGIN_SRC perl :results value
+10 + 20
+#+END_SRC
+
+#+RESULTS:
+#+begin_example
+30
+#+end_example
+
+When returning an array, it is important to return a reference to the array. Otherwise it is interpreted as an scalar. 
+
+For example, this returns the size of the array:
+
+#+BEGIN_EXAMPLE
+#+BEGIN_SRC perl :results value
+my @result ;
+$i = 0;
+for $j ('a'..'e')  {
+   $result[$i] = $j;
+   $i ++;
+}
+@result;
+#+END_SRC
+
+#+RESULTS:
+: 5
+#+END_EXAMPLE
+But this returns the values of the array and creates the corresponding table
+
+#+BEGIN_EXAMPLE
+#+BEGIN_SRC perl :results val

[O] how to save script created when executing a babel block?

2018-06-20 Thread dmg
hi everybody,

is there a way to save the script created by babel that is being executed?

thank you,

-- 
--dmg

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



[O] bug report: + is not escaped in org-link-escape

2017-12-06 Thread dmg
hi everybody,

I am running 9.0.10.

org-link-escape only replaces space, [, ], and %

but search in google/gmail is replacing + also.

The simplest solution is to add 43 to org-link-escape-chars:

   org-link-escape-chars is a variable defined in ‘org.el’.
   Its value is (32 91 93 37)

  This variable may be risky if used as a file-local variable.


I use org-link-escape to jump from an email in gnus to gmail by searching
the message-id. But if when the message-id contains +, this character
must be escaped.

thank you,

-- 
--dmg

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


Re: [O] how to select a source code block and print it to a postscript file

2017-09-09 Thread dmg
I invested a bit more time (plus a couple of suggestions of members of this
list and stackoverflow.) I was able to create a module that prints the
current source block to PDF
without using the exporter. It now uses the pdf viewer to open it.

It might be useful to some people who simply need to create a PDF from a
source block and have it open in the corresponding PDF application:


I look at your suggestions, which pointed me in the direction I needed.
At the end I realized what I wanted was simply to export the current
block to PDF without using the latex exporter. So I simply make the
selection and print that selection to ps, then convert to pdf, and open
using org-open



--
(defcustom dmg-org-src-export-pdf-font-size 12
   "Size of font to use "
  :type 'number
  :version 25
  :group 'dmg-org-src-export-pdf)

(defcustom dmg-org-src-export-pdf-file-name "/tmp/source.code"
   "Name of the file to export as postscript "
  :type 'string
  :version 25
  :group 'dmg-org-src-export-pdf)


(defun dmg-org-src-export-pdf ()
  "show the source code in xournal as a PDF"
  (interactive)
  (save-restriction
(save-excursion
   (unless (executable-find "ps2pdf")
  (error "ps2pdf not found"))

  (let ((element (org-element-at-point))
)
(unless (eq (org-element-type element) 'src-block)
  (error "Not in org-src-block"))
)

  (let* (
 (output-file
      (or (cdr (assq :tangle (nth 2 (org-babel-get-src-block-info
'light
  dmg-org-src-export-pdf-file-name))
 (ps-file (concat output-file ".ps"))
 (pdf-file (concat output-file ".pdf"))
 ;; this uses dynamic scoping to set the parameters of ps
temporarily
 (ps-font-size dmg-org-src-export-pdf-font-size)
 )
(message "Exporting: %s" ps-file)
(org-babel-mark-block)
(narrow-to-region (region-beginning) (region-end))
(ps-print-buffer-with-faces  ps-file)
(shell-command (concat "ps2pdf " ps-file " " pdf-file))
(delete-file ps-file)
(org-open-file pdf-file)
)
  )))


On Sat, Sep 9, 2017 at 2:25 AM, dmg  wrote:

> hi everybody,
>
> I teach programming and I have been using org-mode for a couple years to
> do it. I absolutely love it.
> Lately I have been thinking that I would like to be able to draw on the
> source code using xournal
> (using a tablet)
>
> To do that, I need to generate a pdf. But I don't want to generate the PDF
> of the entire file,
> just of the block I am currently positioned at. I wrote the following
> code, but it feels clumsy, and
> I am not a very good emacs-lisp programmer. I put it together by
> extracting code here and there.
>
> Is there a better way to run ps-print-buffer (or ps-print-region) on the
> current block?
> I am currently using the :tangle parameter as a filename to be created
> (adding the extension .ps)
>
> the script I am running takes the postscript file, generate a pdf, and
> then runs xournal on it.
>
> thank you in advance for any suggestions,
>
> (defun org-src-xournal ()
>   "show the source code in xournal as a PDF"
>   (interactive)
>   (save-restriction
> (save-excursion
>   (let* ((case-fold-search t)
> (tangle-file
>  (or (cdr (assq :tangle (nth 2 (org-babel-get-src-block-info
> 'light
>  (user-error "Point is not in a source code block or it
> does not have a tangle name")))
> (blockp (org-between-regexps-p "^[ \t]*#\\+begin_.*"
>"^[ \t]*#\\+end_.*"))
> (ps-file (concat tangle-file ".ps"))
> )
>
> (message "Exporting: %s" ps-file)
> (if blockp
> (let ((block-start
> (progn (goto-char (car blockp))
> (next-line)
> (point)
>   ))
>   (block-end
> (progn (goto-char (cdr blockp))
>     (previous-line)
>     (point)
>   ))
>   )
>   (narrow-to-region block-start block-end))
>   (user-error "Not in a block"))
> (ps-print-buffer-with-faces ps-file)
> (shell-command (concat "code-xournal " ps-file "&"))
> )
>   )))
>
>
> --
> --dmg
>
> ---
> Daniel M. German
> http://turingmachine.org
>



-- 
--dmg

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


[O] how to select a source code block and print it to a postscript file

2017-09-09 Thread dmg
hi everybody,

I teach programming and I have been using org-mode for a couple years to do
it. I absolutely love it.
Lately I have been thinking that I would like to be able to draw on the
source code using xournal
(using a tablet)

To do that, I need to generate a pdf. But I don't want to generate the PDF
of the entire file,
just of the block I am currently positioned at. I wrote the following code,
but it feels clumsy, and
I am not a very good emacs-lisp programmer. I put it together by extracting
code here and there.

Is there a better way to run ps-print-buffer (or ps-print-region) on the
current block?
I am currently using the :tangle parameter as a filename to be created
(adding the extension .ps)

the script I am running takes the postscript file, generate a pdf, and then
runs xournal on it.

thank you in advance for any suggestions,

(defun org-src-xournal ()
  "show the source code in xournal as a PDF"
  (interactive)
  (save-restriction
(save-excursion
  (let* ((case-fold-search t)
(tangle-file
 (or (cdr (assq :tangle (nth 2 (org-babel-get-src-block-info
'light
 (user-error "Point is not in a source code block or it
does not have a tangle name")))
(blockp (org-between-regexps-p "^[ \t]*#\\+begin_.*"
   "^[ \t]*#\\+end_.*"))
(ps-file (concat tangle-file ".ps"))
)

(message "Exporting: %s" ps-file)
(if blockp
(let ((block-start
(progn (goto-char (car blockp))
(next-line)
(point)
  ))
  (block-end
(progn (goto-char (cdr blockp))
(previous-line)
(point)
  ))
  )
  (narrow-to-region block-start block-end))
  (user-error "Not in a block"))
(ps-print-buffer-with-faces ps-file)
(shell-command (concat "code-xournal " ps-file "&"))
)
  )))


-- 
--dmg

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


Re: [O] Bug report: export to HTML does not escape * in example

2017-02-27 Thread dmg
On Sun, Feb 26, 2017 at 11:40 PM, Nicolas Goaziou 
wrote:

>
> A star at the beginning of a line is always a headline. It has
> precedence over the block around it. You need to escape the star
> character:
>
>   #+begin_example
>   ,* hello world
>   #+end_example
>
> Regards,


​Thank you. I guess the issue is then with org-babel.

I am running a babel script that generates, as one of its line * in the
front:

​#+BEGIN_SRC sh
echo "* Hello"
#+END_SRC

#+RESULTS:
#+begin_example
* Hello
#+end_example

​In that case, should babel be the one escaping the * in the RESULTS block?

thanks again,

--daniel​




-- 
--dmg

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


[O] Bug report: export to HTML does not escape * in example

2017-02-26 Thread dmg
The following example:


* Example

#+begin_example
hello world
#+end_example

#+begin_example
* hello world
#+end_example

exports an HTML file where the second "hello word" is interpreted as a
header, ignoring that it is within begin_example. See below

I am using org-mode version 9.0.3, under emacs-25.




Table of Contents


1. Example
2. hello world 2




1 Example


hello world 1



#+beginexample




2 hello world
2


#+endexample








-- 
--dmg

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


[O] bug report: ox-html with coderef links needs a space between attributes in element (with patch)

2017-01-24 Thread dmg
Hi everybody,

I have the following org-snippet:

---
This is an example

#+BEGIN_SRC sml -r -l "(*(ref:%s)*)" -n
val x = 1
fun f y = x + y (*(ref:f)*)
val x = 2
val y = 3
val z = f(x+y) (*(ref:callf)*)
#+END_SRC

- Line [[(f)]] defines a function that, when called, evaluates body *x+y*
  in environment where *x* maps to *1* and *y* maps to the argument
--
The HTML that it generates creates invalid HTML (one parser used by my
university refuses to accept  it :)

I have inspected the code and this is where it fails: Note how there is no
space between " and class in the  element:


Line 2 defines a function
that, when called, evaluates body x+y
in environment where x maps to 1 and y maps to the
argument


​I am running version 9.0.3 of org.

I believe this patch will solve the issue. It simply adds a space before
the class attribute.

​
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index a741142..9b40cc9 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -3058,7 +3058,7 @@ INFO is a plist holding contextual information.  See
   (let ((fragment (concat "coderef-" (org-html-encode-plain-text
path
(format "%s"
fragment
-   (format "class=\"coderef\"
onmouseover=\"CodeHighlightOn(this, \
+   (format " class=\"coderef\"
onmouseover=\"CodeHighlightOn(this, \
 '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
fragment fragment)
attributes

-- 
--dmg

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


[O] function to select text of in a cell of a table

2016-12-30 Thread dmg
hi everybody,

has anybody written a function to select the text in a cell of a table?

I needed to write a macro/command, but could not find one. Ideally it
should trim the whitespace in the ends.

Otherwise, I'll just write one.

thank you,

--daniel

-- 
--dmg

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


[O] question about org-coderef-label-format and HTML export

2016-12-05 Thread dmg
hi everybody,

I was playing with org-coderef-label-format to reference lines of code
in blocks.

I created a small example that overrides the default value:

#+BEGIN_SRC C++ :main no :flags -std=c++14 -Wall --pedantic -Werror
:results output :exports both -r -l "//(ref:%s)" +n
#include 
int main()
{ //(ref:abc)
   std::cout << "Hello world" << std::endl;
   std::cout << "Hello world 2" << std::endl;
   //(ref:jump)
   return 0;
}
#+END_SRC

#+RESULTS:
#+begin_example
Hello world
Hello world 2
#+end_example

In line [[(abc)]] we remember the current position.  [[(jump)][Line (jump)]]
jumps to point-min.

This seem to work, except for one issue.

the refs are exported to the HTML file:

It only sports the label, not the reference name. See below. Note
how //ref:(abc) in the source code was replaced with //(abc)

{ // (abc)

Is this the expected behaviour? or am I doing something wrong?

my version of org-mode is:

9.0.1

thank you!

--daniel

-- 
--dmg

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



[O] adding code before org-babel sql execution (postgres engine)

2016-09-06 Thread dmg
Hi there

I have been using or-sql with postgres backend for a long time.
There has been one annoyance that I finally fixed.

When the SQL command has an error, it simply outputs
and empty table:

#+begin_src sql :engine postgresql :cmdline  imdb
select * from abc
#+end_src

#+RESULTS:

The error is not detected. I read the documentation of psql and the problem
seems to be that psql does not return an error code by default (even with
invalid
commands).

This can be fixed two ways:

1. add to ~/.psqlrc

\set ON_ERROR_STOP on

2. By adding to the command, before it is executed by babel, this line. In
non-interactive mode psql will stop in the first error with an error code
and babel will catch it:

psql:/tmp/babel-51865ab/sql-in-5186Wyu:1: ERROR:  relation "abc" does not
exist
LINE 1: select * from abc
  ^
I am willing to implement #2, but the question is, is there a clean, easy
way
to do this? Any hints on how to do it?

thank you very much,

--daniel




-- 
--dmg

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


[O] wishful thinking: using SQL to process tables. in the meantime, use R

2016-07-20 Thread dmg
Hi everybody,

I was wondering if there was a way to join two tables given
a common column. I searched but found nothing.

it would be awesome to be able to process tables in SQLITE.
something like this:

#+BEGIN_SRC sqlite :var a=table1 b=table2  :colnames yes
  select * from $a join $b using column;
#+END_SRC

I think it is not that hard. The infrastructure is there already.
It is just a matter of creating temp tables (this is the major part missing
which implies making a create statement from the table, but given
that sqlite is very type agnostic, it might not be hard),
load them from the CSV files
the execute the block. A db parameter might be needed
for a scratch database file, but it could be a temporary one if
none is provided.

But in the meantime, it occurred to me, it is simple in R to do the join
and might be useful to others:

#+BEGIN_SRC R :var a=table1 b=table2 :results value :colnames yes
merge(a,b,by.x="column")
#+END_SRC

merge can do left joins, right joins, full joins, joins,

https://stat.ethz.ch/R-manual/R-devel/library/base/html/merge.html

but there is nothing like the power of SQL to process tables, though.

-- 
--dmg

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


Re: [O] how to update and add info to babel documentation?

2016-07-19 Thread dmg
Thanks Tom,

Here is my patch.


On Tue, Jul 19, 2016 at 10:05 AM, Thomas S. Dye  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
From 67f1d69ea3de516fd46ce8bc74d0b11f3d06cdc4 Mon Sep 17 00:00:00 2001
From: D German 
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=
+and referred in the code block as $.
+
+ - 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



[O] how to update and add info to babel documentation?

2016-07-18 Thread dmg
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


Re: [O] evaluation of perl in babel

2013-02-25 Thread dmg
On Mon, Feb 25, 2013 at 1:54 AM, D M German  wrote:
>
>  Achim> You may misunderstand some things, or I don't understand what you are
>  Achim> asking.  It is (at least currently) the responsibility of the Perl
>  Achim> program (or any other Babel language) to deliver the result in such a
>  Achim> way that it can be interpreted correctly by the result type chosen (in
>  Achim> other word, the program output must be valid Org syntax in the given
>  Achim> context).  You can't have the same program produce tables, vectors and
>  Achim> LaTeX output just by switching the results type.
>
> I understand. But what I want is the output to be wrapped accordingly,
> and my script to deliver exactly the output as expected. So say I want
> to generate HTML in my script, I can use :results output, but then I
> have to change to replace the #+being_example with #+begin_HTML.
>
> I guess that I can generate a two dimensional table with perl too
> using output (printing the necessary | and \n), but then it will be
> wrapped with #+begin_example.

Ok, I got it. What I need is to return a string with whatever I need.
A bit cumbersome, but I can live with it


#+begin_src perl :results html
"
a 

"
#+end_src

#+RESULTS:
#+BEGIN_HTML

a 

#+END_HTML

thanks again for the explanation,

-- 
--dmg

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



Re: [O] evaluation of perl in babel

2013-02-24 Thread dmg
Mm, I didn't include :results value

I think that :results value should do what it does now: return the
value of the last expression.

--dmg

On Sun, Feb 24, 2013 at 1:08 PM, D M German  wrote:
>
> Hi Everybody,
>
> I looked a bit more onto the way that perl is evaluated. I know the
> support of perl is minor. I understand that, so please, don't see this
> message as a complaint, so this is more for discussion and potential
> improvements of the Perl support in Babel.
>
> One of the things I have noticed is that the way that Babel handles the
> results coming from the code is not the best.
>
> Let me elaborate:
>
> At the bottom you will find a set of test that stress the different
> :results types.
>
> There are some bugs. For example, the interpretation of :results table,
> vector and list.
>
> But I think the main problem comes from the way that Babel expects the
> result. In Babel, and except for :results output, the last expression in
> perl is considered the input to the results. This is implementing by
> saving the last expression into a variable, and printing each value
> separated by a "\n" (including the last). So basically, org takes the
> last expression, and outputs them to the babel input file one per line.
>
> This places some constraints. First, it is not currently capable of
> dealing with two dimensional arrays. Second, it makes it hard to create
> complex output (such as HTML or LaTeX), and third, it is hard to debug
> without first printing the value of the array (this output would be lost
> during the evaluation, so it would have be debugged outside org).
>
> I feel that a better approach is to use std output as the default input
> to any of these :results types, and then try to parse them into the
> corresponding :results types. This will allow the creation of HTML and
> LaTeX from perl (which the current implementation does not allow).
>
> So recapitulating, my suggestion is that perl should use STDOUT as the
> output of the snippet in any :results type, rather than the result of
> the last expression.
>
> I know this will break backwards compatibility. One solution is to keep
> the current src perl and add a new perl_stdout mode (or something like
> that) that implements this.
>
> --dmg
>
>
>
> --
> #+begin_src perl :results output
> print "Test\n";
> (1, 2)
> #+end_src
>
> #+RESULTS:
> : Test
>
> #+name: t_output_raw
> #+begin_src perl :results raw
> print "Test\n";
> (1, 2)
> #+end_src
>
> #+RESULTS: t_output_raw
> 1
> 2
>
> #+name: t_output_table
> #+begin_src perl :results table
> print "Test\n";
> (1, 2)
> #+end_src
>
> #+RESULTS: t_output_table
> | 1\n2\n |
>
> #+name: t_output_vector
> #+begin_src perl :results vector
> print "Test\n";
> (1, 2)
> #+end_src
>
> #+RESULTS: t_output_vector
> | 1\n2\n |
>
>
> #+name: t_output_list
> #+begin_src perl :results list
> print "Test\n";
> (1, 2)
> #+end_src
>
> #+RESULTS: t_output_list
> #+begin_example
> - 1
> 2
> #+end_example
>
> #+name: t_output_org
> #+begin_src perl :results org
> print "Test\n";
> (1, 2)
> #+end_src
>
> #+RESULTS: t_output_org
> #+BEGIN_SRC org
> 1
> 2
> #+END_SRC
>
> #+name: t_output_html
> #+begin_src perl :results html
> print "Test\n";
> (1, 2)
> #+end_src
>
> #+RESULTS: t_output_html
> #+BEGIN_HTML
> 1
> 2
> #+END_HTML
>
> #+name: t_output_latex
> #+begin_src perl :results latex
> print "Test\n";
> (1, 2)
> #+end_src
>
> #+RESULTS: t_output_latex
> #+BEGIN_LaTeX
> 1
> 2
> #+END_LaTeX
> --
>
>
> --
> Daniel M. German  "I see no good reason why the
>views given in this volume
>should shock the religious
>Charles Darwin ->   feelings of anyone."
> http://turingmachine.org/
> http://silvernegative.com/
> dmg (at) uvic (dot) ca
> replace (at) with @ and (dot) with .
>
>



-- 
--dmg

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



Re: [O] bug in expansion of variables in babel Perl

2013-02-24 Thread dmg
Mm, I also noticed that when :results output is used, there is no way
to insert perl code before or after the executed code.
org-babel-perl-wrapper-method only works for all the methods but
output. It would be nice to have a variable that
does this for any output type.

--dmg

On Sun, Feb 24, 2013 at 1:16 AM, D M German  wrote:
>
> Hi Everybody,
>
> I found a bug in the Babel perl code. When a table is used as input, the
> values of the table  are not escaped. In fact, they are surrounded by
> double quotes " instead of single ones '. This means that special
> characters are interpreted: $, and @ variables. See below.
>
>
--dmg

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



Re: [O] babel and postgresql

2013-02-23 Thread dmg
It looks like my inexperience with Lisp made me ignore the obvious.
What is needed is not my patch below, but to add posgresql to the
condition of the case:

From:
(case (intern engine)
  ('mysql


To:

(case (intern engine)
  ('(postgresql mysql)

the problem is that I can't get it to work (and I could not find good
documentation for the case macro anywhere but its definition. It says
that it takes either an atom (i.e. 'mysql)
or a list (i.e. '(postgresql mysql) ) but it just does not work me.

But the code for mysql and postgres seems to be the same.

Sorry for the confusion.

--daniel

On Sat, Feb 23, 2013 at 10:42 PM, dmg  wrote:
> Hi everybody, Eric,
>
> I have been starting using Babel with postgresql, R and perl, and I am
> loving it. I really want to thank everybody for their work.
>
> I have found one particular issue that bothers me.
>
> Say I have the following babel section:
>
> #+name: abc
> #+begin_src sql :engine postgresql :cmdline mydb
> select * from aliases limit 1;
> #+end_src
>
> the output is:
>
> #+name: abc
> | alias | uniname  |
> | Jon | jon  |
>
> Note how the column names are not separated from the body:
>
> What I want it this:
>
> #+name:
> | alias | uniname  |
> |---+--|
> | Jon | jon  |
>
> I have tracked the problem, and it is that in ob-sql.el the code of
> org-babel-execute:sql thinks that postgres will return a header separator,
> and it does not.
>
> I am not sure what is the best way to fix it, but I have come with a
> patch that does it (but replaced the older code). The code in
> org-babel-execute:sql
> needs to be modified so it does this only for the postgres backend:
> split the list into first member and rest and insert a 'hline in
> between. My solution is rough, but it works (sorry, I am just an elisp 
> beginner)
>
>
> diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
> index 3586ec9..95cac85 100644
> --- a/lisp/ob-sql.el
> +++ b/lisp/ob-sql.el
> @@ -170,11 +170,12 @@ This function is called by 
> `org-babel-execute-src-block'."
>   )
> (org-table-import out-file '(16))
> (org-babel-reassemble-table
> -(mapcar (lambda (x)
> -  (if (string= (car x) header-delim)
> -  'hline
> -x))
> -(org-table-to-lisp))
> +(funcall (lambda (x)
> +   (cons (car-safe x)
> + (cons 'hline (cdr-safe x))
> + )
> +   )
> +       (org-table-to-lisp))
>  (org-babel-pick-name (cdr (assoc :colname-names params))
>   (cdr (assoc :colnames params)))
>  (org-babel-pick-name (cdr (assoc :rowname-names params))
>
>
>
> --
> --dmg
>
> ---
> Daniel M. German
> http://turingmachine.org



-- 
--dmg

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



[O] babel and postgresql

2013-02-23 Thread dmg
Hi everybody, Eric,

I have been starting using Babel with postgresql, R and perl, and I am
loving it. I really want to thank everybody for their work.

I have found one particular issue that bothers me.

Say I have the following babel section:

#+name: abc
#+begin_src sql :engine postgresql :cmdline mydb
select * from aliases limit 1;
#+end_src

the output is:

#+name: abc
| alias | uniname  |
| Jon | jon  |

Note how the column names are not separated from the body:

What I want it this:

#+name:
| alias | uniname  |
|---+--|
| Jon | jon  |

I have tracked the problem, and it is that in ob-sql.el the code of
org-babel-execute:sql thinks that postgres will return a header separator,
and it does not.

I am not sure what is the best way to fix it, but I have come with a
patch that does it (but replaced the older code). The code in
org-babel-execute:sql
needs to be modified so it does this only for the postgres backend:
split the list into first member and rest and insert a 'hline in
between. My solution is rough, but it works (sorry, I am just an elisp beginner)


diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 3586ec9..95cac85 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -170,11 +170,12 @@ This function is called by `org-babel-execute-src-block'."
  )
(org-table-import out-file '(16))
(org-babel-reassemble-table
-(mapcar (lambda (x)
-  (if (string= (car x) header-delim)
-  'hline
-x))
-(org-table-to-lisp))
+(funcall (lambda (x)
+   (cons (car-safe x)
+ (cons 'hline (cdr-safe x))
+ )
+   )
+   (org-table-to-lisp))
 (org-babel-pick-name (cdr (assoc :colname-names params))
  (cdr (assoc :colnames params)))
 (org-babel-pick-name (cdr (assoc :rowname-names params))



-- 
--dmg

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



Re: [O] a window with my agenda at all times

2011-06-27 Thread dmg
here is a patch worg (org-hacks.org) describing the hack.

Hopefully somebody with write access to can commit it.

--dmg
diff --git a/org-hacks.org b/org-hacks.org
index 024eaf3..19b67c9 100644
--- a/org-hacks.org
+++ b/org-hacks.org
@@ -2259,3 +2259,30 @@ position in the track.
 
 See the file [[file:code/elisp/org-player.el][org-player.el]]
 
+** Under X11 Keep a window with the current agenda items at all time
+
+I struggle to keep (in emacs) a window with the agenda at all times.
+For a long time I have wanted a sticky window that keeps this
+information, and then use my window manager to place it and remove its
+decorations (I can also force its placement in the stack: top always,
+for example).
+
+I wrote a small program in qt that simply monitors an HTML file and
+displays it. Nothing more. It does the work for me, and maybe somebody
+else will find it useful. It relies on exporting the agenda as HTML
+every time the org file is saved, and then this little program
+displays the html file. The window manager is responsible of removing
+decorations, making it sticky, and placing it in same place always.
+
+Here is a screenshot (see window to the bottom right). The decorations
+are removed by the window manager:
+
+http://turingmachine.org/hacking/org-mode/orgdisplay.png
+
+Here is the code. As I said, very, very simple, but maybe somebody will
+find if useful.
+
+http://turingmachine.org/hacking/org-mode/
+
+--daniel german
+


Re: [O] a window with my agenda at all times

2011-06-27 Thread dmg
On Mon, Jun 27, 2011 at 12:42 PM, Bastien  wrote:
> Hi Mr German,
>
> D M German  writes:
>
>> For a long time I have wanted a sticky window that keeps this
>> information. Like a sticky note on my desktop (think a widget in
>> Android).
>
> I would use a new frame:
>
> C-x 5 2 ; create a new frame
> C-c a a ; create a new agenda

I used to that too, but the new frame gets on the way, and it is
difficult to control its placement and
window decorations using the window manager.


> Nice - could you mention it on Worg?
>
>  http://orgmode.org/worg/org-hacks.html

I will


>
> Thanks!
>
> --
>  Bastien
>



-- 
--dmg

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



Re: [Orgmode] Re: org-protocol: non-ASCII characters

2010-02-12 Thread dmg
> Basically, it is OK to url-encode each character who's binary
> representation start with 1 (i.e., the value of the character is higher
> than 127). The text to be url-encoded should be UTF-8 ideally.
>
> If you use glib::ustring, it's easy to transform any iso-8859 string to
> utf-8. Each character, whos binary representation start with a 1, has to
> be url-encoded as well as the `%' character [1], but you could as
> url-encode the entire utf-8 string.
>
>

Ok, I think I understand the problem now. I have updated xournal to encode the
filename from its encoding to uft8. that seems to work. See

http://github.com/dmgerman/xournal

For evince, I think I have found a problem in the parsing of the link.
Evince already encodes
the URL, but it does not encode the '/', hence you will get a link like this:

emacsclient 
'org-protocol://remember://docview/tmp/00%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA.pdf::1'

the filename is  /tmp/00áéíóú.pdf

But emacs incorrectly stops parsing the link after tmp/

By the way, xournal now supports store-link


--dmg

>
>
>
>
> The function that does the decoding is `org-protocol-unhex-string' which
> in turn uses `org-protocol-unhex-compound'.
>
>
> `man utf-8` shows, how org-protocol tries to decode characters.
>
>
> The JavaScript-Funktion `encodeURIComponent()' returns exactly what we
> need. It recodes a string to utf-8 and then encodes all characters,
> except digits, ASCII letters and these punctuation characters: -_.!~*'()
>
> See ECMA-262 Standard, Section 15.1.3
> (http://bclary.com/2004/11/07/ecma-262.html#a-15.1.3 [2]):
>
>   "The character is first transformed into a sequence of octets using
>    the UTF-8 transformation..."
>
>
> Again, note, that the decoding mechanism relies on the fact, that the
> sequence to decode is url-encoded UTF-8.
>
>
>
>
>
> Example:
>
>  The url-encoded unicode representation of the German umlaut `ö' is
>  `%C3%B6'. Thus
>
>     (org-protocol-unhex-string "%C3%B6")
>
>  gives you "ö".
>
>  In iso-8859-1, the url-encoded representation of the same character `ö' was
>  `%F6'. But
>
>     (org-protocol-unhex-string "%F6")
>
>  gives you "" - the empty string. There is no utf-8 character with this binary
>  representation, since every byte starting with a 1 (i.e. is bigger than 127)
>  starts a multibyte sequence (2 or more bytes).
>
>  But:
>
>     (org-protocol-unhex-string "%2F%3C")
>
>  gives you, as expected,  "/<" which shows, that you could savely
>  url-encode each and every character of a utf-8 encoded string.
>
>
> ==  Footnotes:
>
> [1] The percent character `%' has to be encoded, if followed by
>    [0-9A-Fa-f]{2}, because org-protocol will assume, that a sequence
>    matching "\\(%[0-9a-f][0-9a-f]\\)+" is an encoded character. That
>    said, a `%' has to be url-encoded, since one will hardly ever
>    know for sure, that a `%' is never followed by "[0-9a-f][0-9a-f]".
>
> [2] Get a PDF version of ECMA-262 third edition here:
>    http://www.ecma-international.org/publications/standards/Ecma-262.htm
>
>



-- 
--dmg

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


___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] org-remember support in xournal

2010-02-03 Thread dmg
On Wed, Feb 3, 2010 at 1:19 AM, Jan Böcker  wrote:
>> Hi everybody,
>>
>> I am sorry I have been a bit slow to finish the integration of xournal
>> with remember mode. I think I got it working.
>
> Hi Daniel,
>
> that is great!
>
> After learning about org-protocol on worg, I got it working.

good. first person who uses it beside me!

> There seems to be a problem with non-ASCII characters in the file names,
> though: an "ü" in the file path arrived in emacs as "%0 %))".

I wonder if that would have been a problem. I had to write my own
functions to encode the
non alphanumeric characters. I'll look into it, but will have to wait
until next week.


>
>> If the loaded file in xournal is a PDF, the remember link is created to
>> the .pdf file. Otherwise it is created to the .xoj file.
>>
>> In both cases the protocol is docview:
>>
>> emacsclient 'org-protocol://remember://docview:filename::pagenumber
>
> Can you add a second menu item ("Store Link"), which uses
> 'org-protocol://store-link://docview:filename::pagenumber'?
>

I will. Next week though.


> - Jan
>
>



-- 
--dmg

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


___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


[Orgmode] Re: org-remember support in xournal

2010-01-31 Thread dmg
>
> My branch of xournal is available at github:
>
> http://github.com/jboecker/xournal

My apologies. I pointed to the wrong branch of xournal, mine is:

http://github.com/dmgerman/xournal

--dmg


___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode