From mboxrd@z Thu Jan 1 00:00:00 1970 From: Subhan Tindall Subject: patch for support of oracle/sqlplus - please review Date: Wed, 9 Oct 2013 16:03:45 -0700 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e0160b7beaf26dd04e856e55c Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52912) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VU2nI-0005Yk-8p for emacs-orgmode@gnu.org; Wed, 09 Oct 2013 19:03:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VU2nD-0004fT-Gb for emacs-orgmode@gnu.org; Wed, 09 Oct 2013 19:03:52 -0400 Received: from mail-la0-f53.google.com ([209.85.215.53]:54352) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VU2nD-0004f6-5F for emacs-orgmode@gnu.org; Wed, 09 Oct 2013 19:03:47 -0400 Received: by mail-la0-f53.google.com with SMTP id el20so1316935lab.26 for ; Wed, 09 Oct 2013 16:03:45 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org-Mode --089e0160b7beaf26dd04e856e55c Content-Type: text/plain; charset=ISO-8859-1 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 --089e0160b7beaf26dd04e856e55c Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
This patch adds support for oracle databases in= code blocks using sqlplus.
Strictly speaking all that is n= ecessary is the addition of the .sql extension to in-file-name, however I a= lso 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 @@
=A0;; - support for more engines (currently only supports mysql)
=
=A0;; - what's a reasonable way to drop table data into SQL?
=
=A0;;
+;; CHANGES:
+;;
+;; - smt 10/8/13=
+;; - added support for oracle using sqlplus. Included header args
+;; -- dbuser, dbpassword, dbhost. =A0Added
+;; - added .s= ql extension to in-file-name for oracle support
=A0
=A0= ;;; Code:
=A0(require 'ob)
@@ -98,7 +104,7 @@ This function is cal= led by `org-babel-execute-src-block'."
=A0 =A0 =A0 =A0 = =A0 (database (cdr (assoc :database params)))
=A0 =A0 =A0 =A0 =A0= (engine (cdr (assoc :engine params)))
=A0 =A0 =A0 =A0 =A0 (colnames-p (not (equal "no" (cdr (assoc= :colnames params)))))
- =A0 =A0 =A0 =A0 (in-file (org-babel-temp= -file "sql-in-"))
+ =A0 =A0 =A0 =A0 (in-file (org-babel= -temp-file "sql-in-" ".sql"))
=A0 =A0 =A0 =A0 =A0 (out-file (or (cdr (assoc :out-file params))
=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (org-babel-temp-file &= quot;sql-out-")))
=A0 =A0 =A0 =A0 =A0(header-delim "&qu= ot;)
@@ -127,6 +133,30 @@ This function is called by `org-babel-e= xecute-src-block'."
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 (org-babel-process-file-name in-file)
=A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (org-babel-process-file-na= me out-file)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 (or cmdline "")))
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0('oracle (format
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"sqlplu= s -s %s"
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 (cond ( (and dbuser dbhost dbpassword)
+ =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (format "%s/%s= @%s @%s > %s"
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 dbuser dbpassword dbhost
+ =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (or= g-babel-process-file-name in-file)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (org-babel-proc= ess-file-name out-file)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 )
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ) ;; user specified dbuser, dbpassword, &am= p; dbhost
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 ( (or dbuser dbhost dbpassword)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 (error (format "Must specify dbuser/dbpassword@dbhost, missing %s = %s %s"
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(if dbuser ""= ":dbuser")
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(if dbpassword "" ":dbpas= sword")
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(if dbhost "&qu= ot; ":dbhost")
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0)
+ =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0)
+ = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ) ;= ; if one specified, they all must be
+ =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ( t
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 (format "%s @%s > %s"
+ =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (or cmdline= "")
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (org-babel-process-file-name in-fil= e)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 (org-babel-process-file-name out-file)
+ =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 )
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 ))))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0(t (error "No support for the %s SQL engine" engine)))))
=A0 =A0 =A0(with-temp-file in-file
=A0 =A0 =A0 =A0(insert


--
Subha= n Michael Tindall | Software Developer
| smt@rentrakmail.com
RENTRAK | www.rentrak= .com | NASDAQ: RENT
--089e0160b7beaf26dd04e856e55c--