emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [babel] (Almost) Add SQL*Plus engine


From: Sebastien Vauban
Subject: [O] [babel] (Almost) Add SQL*Plus engine
Date: Tue, 22 Nov 2011 15:31:30 +0100
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.50 (windows-nt)

Hi Eric,

I almost added the engine `sqlplus' (from Oracle Instant client) to `ob-sql':

#+begin_src emacs-lisp
  ('sqlplus (format "sqlplus -S %s @%s > %s"
                  (or cmdline "")
                  (org-babel-process-file-name in-file)
                  (org-babel-process-file-name out-file)))
#+end_src

where:

- `S' is to remove the Oracle banner
- `user/address@hidden' is the logon info (given as `cmdline')
- address@hidden' is the way to pass an SQL script to be run (file name is 
preceded by
  an `@' sign).

BUT the code block to be executed is saved by Babel in Windows' TEMP
directory, for example under a file whose full path is:

    c:\WINDOWS\TEMP\babel-511607b\sql-in-5116n4J

There is no file extension there. This becomes important... as SQL*Plus seems
to always add the `sql' extension to the script file name, when they don't
have one:

#+begin_src sh
  $ sqlplus -S user/address@hidden 
@c\:/WINDOWS/TEMP/babel-511607b/sql-in-5116n4J
                                                                ^^^^^^^^^^^^^^
  SP2-0310: unable to open file 
"c:/WINDOWS/TEMP/babel-511607b/sql-in-5116n4J.sql"
#+end_src                                                      
^^^^^^^^^^^^^^^^^^

If I go and add an `sql' extension to that temporary file, in the file system,
the script is well read and executed:

#+begin_src sql
  $ sqlplus -S user/address@hidden 
@c\:/WINDOWS/TEMP/babel-511607b/sql-in-5116n4J.sql
                                                                
^^^^^^^^^^^^^^^^^^
  SELECT * FROM employees
                *
  ERROR at line 1:
  ORA-00942: table or view does not exist
#+end_src

Here, the command is executed, but fails because it's just a sample command,
and there is no such table.

So, in order to get the `sqlplus' engine working, it seems necessary to add
the language extension to the file name hosting temporarily the code snippet.

In a way, it's even cleaner: would we open it under Emacs, we directly get the
proper highlighting, etc. But there was maybe a reason it hadn't been done
that way?

What do you think?

Best regards,
  Seb

-- 
Sebastien Vauban




reply via email to

[Prev in Thread] Current Thread [Next in Thread]