add support for MonetDB to SQL code blocks
commitbd3b1aee2f7e92093f26efe19800d542ef8b19f0
authorViktor Rosenfeld <listuser36@googlemail.com>
Sat, 25 Feb 2012 16:43:13 +0000 (25 09:43 -0700)
committerEric Schulte <eric.schulte@gmx.com>
Sat, 25 Feb 2012 16:44:18 +0000 (25 09:44 -0700)
tree085c44c2ec3e8d632a20a5d33f9fc3cee65f61ad
parent87216ffa56a2714fc245fe9cd64ff9fa93f84be6
add support for MonetDB to SQL code blocks

* lisp/ob-sql.el(org-babel-execute:sql): Add support for MonetDB to
  SQL code blocks.

  Hi,

  the attached patch adds support for evaluating SQL blocks on MonetDB.
  The MonetDB client normally requires the password to be inputted on the
  console. To get around this, you have to use a dotfile ~/.monetdb with
  authentification data. Note that this file is ignored if you specify a
  user on the cmdline. See
  http://www.monetdb.org/Documentation/mclient-man-page for details.

  A usage example follows.

  Setup MonetDB test database and authentification data

  #+BEGIN_SRC sh :results output verbatim
  MONETDB_DIR=$HOME/unix/var/monetdb/demodb
  monetdbd create $MONETDB_DIR
  monetdbd start $MONETDB_DIR
  monetdb create demodb
  monetdb release demodb
  cat > ~/.monetdb <<EOF
  user=monetdb
  password=monetdb
  EOF
  #+END_SRC

  #+RESULTS:
  : created database in maintenance mode: demodb
  : taken database out of maintenance mode: demodb

  Data is returned without column names (the default return format
  cannot be parsed by Babel).

  #+BEGIN_SRC sql :engine monetdb :cmdline demodb
  CREATE TABLE foo ( bar INTEGER );
  SELECT 'Table count', count(*) FROM foo;
  #+END_SRC

  #+RESULTS:
  | Table count | 0 |

  The parameter "-i" is required on the command line in order to use
  special client commands. Also note that a newline is required at the
  end if the last line contains a special client command.

  #+BEGIN_SRC sql :engine monetdb :cmdline demodb -i :results output
  verbatim
  \d
  \?

  #+END_SRC

  #+RESULTS:
  #+begin_example
  TABLE  sys.foo
  \?      - show this message
  \<file  - read input from file
  \>file  - save response in file, or stdout if no file is given
  \|cmd   - pipe result to process, or stop when no command is given
  \h      - show the readline history
  \D table- dumps the table, or the complete database if none given.
  \d[Stvsfn]+ [obj] - list database objects, or describe if obj given
  \A      - enable auto commit
  \a      - disable auto commit
  \e      - echo the query in sql formatting mode
  \f      - format using a built-in renderer {csv,tab,raw,sql,xml}
  \w#     - set maximal page width (-1=unlimited, 0=terminal width,
  >0=limit to num)
  \r#     - set maximum rows per page (-1=raw)
  \L file - save client/server interaction
  \X      - trace mclient code
  \q      - terminate session
  #+end_example

  Have fun!
lisp/ob-sql.el