Sunday, February 26, 2017

emacs - org babel mode - using paramer ex. sql (from:Introduction to Literate Programming)

--> from:
 http://www.howardism.org/Technical/Emacs/literate-programming-tutorial.html





Introduction to Literate Programming

Welcome to a brief tutorial on literate programming in org-mode.
The following began as the basis for a workshop for the PDX Emacs Hackers meetup, but since everyone couldn’t attend, I decided to expand it into a tutorial. I assume you understand the basics of Emacs and as well as familiarity with org-mode for creating exported documents.
As you probably know, Org is pretty large, and the features for writing, evaluating and connecting blocks of source code in a document are extensive, and documenting them all is a daunting task. I hope this tutorial is a good start, but if I glossed over something you feel I should include, please let me know.
Warning: The examples are pretty lame.
--
# -*- coding: utf-8 -*-
#+STARTUP: content
#+LANGUAGE: ko
#+PROPERTY: header-args:sql :engine postgresql :export results :cmdline -p 5432 -h localhost -U kys -d emacsdb PGPASSWORD=pass1234

* example-1. use parameter in the document level defind '#+PROPERTY'
#+BEGIN_SRC sql 
select eng_name, title, fullname from springschema.phonebook;
#+END_SRC


#+RESULTS:
| eng_name  | title | fullname |
|-----------+-------+----------|
| So Wonju  | 대리  | 지원호   |
| Mr.Jung   | 사원  | 김지원   |
..


** example-2. use parameter in the org-heading section of ':PROPERTIES:'
 :PROPERTIES:
 :LANGUAGE: sql
 :engine: postgresql
 :exports: results
 :cmdline: -p 5432 -h localhost -U kys -d emacsdb PGPASSWORD=pass1234
 :END:

#+begin_src sql
select eng_name, title, fullname from springschema.phonebook;
select "select version()";
#+end_src

#+RESULTS:
| eng_name  | title | fullname |
|-----------+-------+----------|
| So Wonju  | 대리  | 지원호   |
| Mr.Jung   | 사원  | 김지원   |
..


* example-3. use in specified src block values
#+BEGIN_SRC sql :engine postgresql :exports results :cmdline -p 5432 -h localhost -U kys -d emacsdb PGPASSWORD=pass123
select eng_name, title, fullname from springschema.phonebook;
#+END_SRC

#+RESULTS:
| eng_name  | title | fullname |
|-----------+-------+----------|
| So Wonju  | 대리  | 지원호   |
| Mr.Jung   | 사원  | 김지원   |

 ※ :results:output 가 있으면 raw 로 encoding 없이 출력된다.
(※ ':results:output' means output without encoding) 


No comments:

Pranten

 Pranten