emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: pierre.techoueyres@free.fr (Pierre Téchoueyres)
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] ob-sql.el: Improve Oracle connection and usage for ob-sql.
Date: Tue, 13 Mar 2018 20:51:44 +0100	[thread overview]
Message-ID: <87po47wy7j.fsf@killashandra.ballybran.fr> (raw)
In-Reply-To: <87po488k1l.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Tue, 13 Mar 2018 09:19:18 +0100")

[-- Attachment #1: Type: text/plain, Size: 201 bytes --]

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> ...
> Otherwise, it looks good. Would you mind adding an entry in ORG-NEWS
> about it?
Hello Nicolas,

What dou you think about the attached patch ?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Use Oracle's alias in ob-sql patch --]
[-- Type: text/x-patch, Size: 2678 bytes --]

From 0103a07b10915ce7c919b8a6858beff3dbd7e45f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pierre=20T=C3=A9choueyres?= <pierre.techoueyres@free.fr>
Date: Thu, 8 Mar 2018 23:37:29 +0100
Subject: [PATCH] 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 allow 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.
---
 etc/ORG-NEWS   | 18 ++++++++++++++++++
 lisp/ob-sql.el | 11 +++++++++--
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 77373d442..11fe4395d 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -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~
 
diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 959ede3de..3ad7906cf 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -111,8 +111,14 @@ 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 args for database connection.
+
+If PORT and DATABASE are nil then don't pass them. This allow you to
+use names defined in your TNSNAMES file."
+  (format "%s/%s@%s%s" user password host
+	  (if (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 +247,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
-- 
2.14.3


  parent reply	other threads:[~2018-03-13 19:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-09 19:51 [PATCH] ob-sql.el: Improve Oracle connection and usage for ob-sql Pierre Téchoueyres
2018-03-13  8:19 ` Nicolas Goaziou
2018-03-13 12:10   ` pierre.techoueyres
2018-03-13 19:51   ` Pierre Téchoueyres [this message]
2018-03-14 13:38     ` Nicolas Goaziou
2018-03-15 18:34       ` Pierre Téchoueyres
2018-03-16 22:03         ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87po47wy7j.fsf@killashandra.ballybran.fr \
    --to=pierre.techoueyres@free.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@nicolasgoaziou.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).