emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Subhan Tindall <subhan.tindall@rentrakmail.com>
To: Org-Mode <emacs-orgmode@gnu.org>
Subject: patch for support of oracle/sqlplus - please review
Date: Wed, 9 Oct 2013 16:03:45 -0700	[thread overview]
Message-ID: <CAKKEbDtfNQvwz1Lh3MF59x2ask5k0fypFaBv0S8UFEtB=kAjjw@mail.gmail.com> (raw)

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

This patch adds support for oracle databases in code blocks using sqlplus.
Strictly speaking all that is necessary is the addition of the .sql
extension to in-file-name, however I also included header line
specification of dbuser, dbpassword, and dbhost


diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 658a54f..5208a20 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -53,6 +53,12 @@
 ;; - support for more engines (currently only supports mysql)
 ;; - what's a reasonable way to drop table data into SQL?
 ;;
+;; CHANGES:
+;;
+;; - smt 10/8/13
+;; - added support for oracle using sqlplus. Included header args
+;; -- dbuser, dbpassword, dbhost.  Added
+;; - added .sql extension to in-file-name for oracle support

 ;;; Code:
 (require 'ob)
@@ -98,7 +104,7 @@ This function is called by
`org-babel-execute-src-block'."
          (database (cdr (assoc :database params)))
          (engine (cdr (assoc :engine params)))
          (colnames-p (not (equal "no" (cdr (assoc :colnames params)))))
-         (in-file (org-babel-temp-file "sql-in-"))
+         (in-file (org-babel-temp-file "sql-in-" ".sql"))
          (out-file (or (cdr (assoc :out-file params))
                        (org-babel-temp-file "sql-out-")))
         (header-delim "")
@@ -127,6 +133,30 @@ This function is called by
`org-babel-execute-src-block'."
                                    (org-babel-process-file-name in-file)
                                    (org-babel-process-file-name out-file)
                                    (or cmdline "")))
+                    ('oracle (format
+                              "sqlplus -s %s"
+                             (cond ( (and dbuser dbhost dbpassword)
+                                     (format "%s/%s@%s @%s > %s"
+                                             dbuser dbpassword dbhost
+                                             (org-babel-process-file-name
in-file)
+                                             (org-babel-process-file-name
out-file)
+                                             )
+                                     ) ;; user specified dbuser,
dbpassword, & dbhost
+                                   ( (or dbuser dbhost dbpassword)
+                                     (error (format "Must specify
dbuser/dbpassword@dbhost, missing %s %s %s"
+                                                    (if dbuser ""
":dbuser")
+                                                    (if dbpassword ""
":dbpassword")
+                                                    (if dbhost ""
":dbhost")
+                                                    )
+                                          )
+                                     ) ;; if one specified, they all must
be
+                                   ( t
+                                     (format "%s @%s > %s"
+                                             (or cmdline "")
+                                             (org-babel-process-file-name
in-file)
+                                             (org-babel-process-file-name
out-file)
+                                             )
+                                     ))))
                     (t (error "No support for the %s SQL engine"
engine)))))
     (with-temp-file in-file
       (insert


-- 
Subhan Michael Tindall | Software Developer
| smt@rentrakmail.com
RENTRAK | www.rentrak.com | NASDAQ: RENT

[-- Attachment #2: Type: text/html, Size: 4503 bytes --]

             reply	other threads:[~2013-10-09 23:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-09 23:03 Subhan Tindall [this message]
2013-11-05 16:56 ` patch for support of oracle/sqlplus - please review Bastien

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='CAKKEbDtfNQvwz1Lh3MF59x2ask5k0fypFaBv0S8UFEtB=kAjjw@mail.gmail.com' \
    --to=subhan.tindall@rentrakmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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).