1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-21 06:55:35 +00:00

ob-sql.el: Improve Oracle connection and usage for ob-sql.

* lisp/ob-sql.el (org-babel-sql-dbstring-oracle): Don't use empty
args.  This allows use of alias defined in Oracle's TNSNAMES files.
(org-babel-execute:sql): Don't feed lines with trailing spaces.  This
also improve speed for retrieving data.
This commit is contained in:
Pierre Téchoueyres 2018-03-08 23:37:29 +01:00 committed by Nicolas Goaziou
parent bc7b24d0d0
commit 0edf344e2a
2 changed files with 24 additions and 2 deletions

View File

@ -199,6 +199,24 @@ you should expect to see something like:
#+BEGIN_EXAMPLE
,#+STARTUP: shrink
#+END_EXAMPLE
*** Add support for Oracle's database alias in Babel blocks
=ob-sql= library already support running SQL blocks against an Oracle
database using ~sqlplus~. Now it's possible to use alias names
defined in =TNSNAMES= file instead of specifying full connection
parameters. See example bellow.
#+BEGIN_SRC org
you can use the previous full connection parameters
,#+BEGIN_SRC sql :engine oracle :dbuser me :dbpassword my_insecure_password :database my_db_name :dbhost my_db_host :dbport 1521
select sysdate from dual;
,#+END_SRC
or the alias defined in your TNSNAMES file
,#+BEGIN_SRC sql :engine oracle :dbuser me :dbpassword my_insecure_password :database my_tns_alias
select sysdate from dual;
,#+END_SRC
#+END_SRC
** New functions
*** ~org-insert-structure-template~

View File

@ -111,8 +111,11 @@ Pass nil to omit that arg."
(when database (concat "-d" database))))))
(defun org-babel-sql-dbstring-oracle (host port user password database)
"Make Oracle command line args for database connection."
(format "%s/%s@%s:%s/%s" user password host port database))
"Make Oracle command line arguments for database connection.
If PORT and DATABASE are nil then don't pass them. This allows
you to use names defined in your \"TNSNAMES\" file."
(concat (format "%s/%s@%s" user password host)
(and port database (format ":%s/%s" port database))))
(defun org-babel-sql-dbstring-mssql (host user password database)
"Make sqlcmd command line args for database connection.
@ -241,6 +244,7 @@ SET NEWPAGE 0
SET TAB OFF
SET SPACE 0
SET LINESIZE 9999
SET TRIMOUT ON TRIMSPOOL ON
SET ECHO OFF
SET FEEDBACK OFF
SET VERIFY OFF