emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* patch for support of oracle/sqlplus - please review
@ 2013-10-09 23:03 Subhan Tindall
  2013-11-05 16:56 ` Bastien
  0 siblings, 1 reply; 2+ messages in thread
From: Subhan Tindall @ 2013-10-09 23:03 UTC (permalink / raw)
  To: Org-Mode

[-- 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 --]

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-11-05 16:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-09 23:03 patch for support of oracle/sqlplus - please review Subhan Tindall
2013-11-05 16:56 ` Bastien

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).