emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Andreas Gerler <baron@bundesbrandschatzamt.de>
To: emacs-orgmode@gnu.org
Subject: [PATCH] ob-sql: Add vertica engine
Date: Mon, 27 Mar 2017 22:24:07 +0200	[thread overview]
Message-ID: <B664B5E8-B6A8-4B20-B0CB-F6149C720718@bundesbrandschatzamt.de> (raw)

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

* lisp/ob-sql.el (org-babel-sql-dbstring-vertica): New function.
(org-babel-execute:sql): Add `vertica' engine.

Signed-off-by: Andreas Gerler <baron@bundesbrandschatzamt.de>
---
 lisp/ob-sql.el | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 15c50ad..ec0427f 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -56,6 +56,7 @@
 ;; - sqsh
 ;; - postgresql
 ;; - oracle
+;; - vertica
 ;;
 ;; TODO:
 ;;
@@ -136,6 +137,16 @@ SQL Server on Windows and Linux platform."
                           (when database (format "-D \"%s\"" database))))
              " "))

+(defun org-babel-sql-dbstring-vertica (host port user password database)
+  "Make Vertica command line args for database connection. Pass nil to omit that arg."
+  (mapconcat #'identity
+	      (delq nil
+		    (list (when host     (format "-h %s" host))
+			  (when port     (format "-p %d" port))
+			  (when user     (format "-U %s" user))
+			  (when password (format "-w %s" (shell-quote-argument password) ))
+			  (when database (format "-d %s" database))))
+	      " "))

 (defun org-babel-sql-convert-standard-filename (file)
   "Convert the file name to OS standard.
@@ -208,6 +219,12 @@ footer=off -F \"\t\"  %s -f %s -o %s %s"
 				    (org-babel-process-file-name in-file))
 				   (org-babel-sql-convert-standard-filename
 				    (org-babel-process-file-name out-file))))
+		    (`vertica (format "vsql %s -f %s -o %s %s"
+				    (org-babel-sql-dbstring-vertica
+				     dbhost dbport dbuser dbpassword database)
+				    (org-babel-process-file-name in-file)
+				    (org-babel-process-file-name out-file)
+				    (or cmdline "")))
                     (`oracle (format
 			      "sqlplus -s %s < %s > %s"
 			      (org-babel-sql-dbstring-oracle
@@ -235,6 +252,7 @@ SET COLSEP '|'
 	 ((or `mssql `sqsh) "SET NOCOUNT ON

 ")
+	 (`vertica "\\a\n")
 	 (_ ""))
        (org-babel-expand-body:sql body params)
        ;; "sqsh" requires "go" inserted at EOF.
@@ -245,7 +263,7 @@ SET COLSEP '|'
 	(progn (insert-file-contents-literally out-file) (buffer-string)))
       (with-temp-buffer
 	(cond
-	 ((memq (intern engine) '(dbi mysql postgresql sqsh))
+	 ((memq (intern engine) '(dbi mysql postgresql sqsh vertica))
 	  ;; Add header row delimiter after column-names header in first line
 	  (cond
 	   (colnames-p
--
2.10.1 (Apple Git-78)


[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 204 bytes --]

             reply	other threads:[~2017-03-27 20:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-27 20:24 Andreas Gerler [this message]
2017-03-30 10:44 ` [PATCH] ob-sql: Add vertica engine Nicolas Goaziou
2017-03-30 13:48   ` Andreas Gerler
2017-03-31  6:48     ` 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=B664B5E8-B6A8-4B20-B0CB-F6149C720718@bundesbrandschatzamt.de \
    --to=baron@bundesbrandschatzamt.de \
    --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).