emacs-orgmode
[Top][All Lists]
Advanced

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

[O] patch for support of oracle/sqlplus - please review


From: Subhan Tindall
Subject: [O] patch for support of oracle/sqlplus - please review
Date: Wed, 9 Oct 2013 16:03:45 -0700

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/address@hidden @%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/address@hidden, 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
| address@hidden
RENTRAK | www.rentrak.com | NASDAQ: RENT

reply via email to

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