[PATCH] ob-sql.el: Add support for SAP HANA

2021-02-03 Thread Robin Campbell Joy
* lisp/ob-sql.el (org-babel-execute:sql, org-babel-sql-dbstring-saphana):
Add basic support for SAP HANA to SQL blocks
* testing/lisp/test-ob-sql.el: Basic tests for generated db connection
string

This change adds basic support for SAP HANA to SQL blocks by
specifying saphana as :engine.

It also adds a new header arg `dbinstance' in order to specify the SAP
HANA instance to connect to.

Signed-off-by: Robin Campbell Joy 
---
 lisp/ob-sql.el  |  25 ++-
 testing/lisp/test-ob-sql.el | 382 
 2 files changed, 406 insertions(+), 1 deletion(-)
 create mode 100644 testing/lisp/test-ob-sql.el

diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 902194ae8..5398c85aa 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -40,6 +40,7 @@
 ;; - dbuser
 ;; - dbpassword
 ;; - dbconnection (to reference connections in sql-connection-alist)
+;; - dbinstance
 ;; - database
 ;; - colnames (default, nil, means "yes")
 ;; - result-params
@@ -58,6 +59,7 @@
 ;; - postgresql (postgres)
 ;; - oracle
 ;; - vertica
+;; - saphana
 ;;
 ;; TODO:
 ;;
@@ -85,6 +87,7 @@
 (dbport   . :any)
 (dbuser   . :any)
 (dbpassword   . :any)
+(dbinstance   . :any)
 (database   . :any))
   "SQL-specific header arguments.")

@@ -174,6 +177,18 @@ SQL Server on Windows and Linux platform."
   (when database (format "-d %s" database
   " "))

+(defun org-babel-sql-dbstring-saphana (host port instance user password
database)
+  "Make SAP HANA command line args for database connection. Pass nil to
omit that arg."
+  (mapconcat #'identity
+ (delq nil
+   (list (when (and host port) (format "-n %s:%s" host
port))
+ (when (and host (not port)) (format "-n %s" host))
+ (when instance (format "-i %d" instance))
+ (when user (format "-u %s" user))
+ (when password (format "-p %s"
(shell-quote-argument password)))
+ (when database (format "-d %s" database
+ " "))
+
 (defun org-babel-sql-convert-standard-filename (file)
   "Convert FILE to OS standard file name.
 If in Cygwin environment, uses Cygwin specific function to
@@ -197,6 +212,7 @@ database connections."
  (:dbport . sql-port)
  (:dbuser . sql-user)
  (:dbpassword . sql-password)
+ (:dbinstance . sql-dbinstance)
  (:database . sql-database)))
  (mapped-name (cdr (assq name name-mapping
 (cadr (assq mapped-name
@@ -212,6 +228,7 @@ This function is called by
`org-babel-execute-src-block'."
  (dbport (org-babel-find-db-connection-param params :dbport))
  (dbuser (org-babel-find-db-connection-param params :dbuser))
  (dbpassword (org-babel-find-db-connection-param params
:dbpassword))
+ (dbinstance (org-babel-find-db-connection-param params
:dbinstance))
  (database (org-babel-find-db-connection-param params :database))
  (engine (cdr (assq :engine params)))
  (colnames-p (not (equal "no" (cdr (assq :colnames params)
@@ -276,6 +293,12 @@ footer=off -F \"\t\"  %s -f %s -o %s %s"
   dbhost dbport dbuser dbpassword database)
  (org-babel-process-file-name in-file)
  (org-babel-process-file-name out-file)))
+(saphana (format "hdbsql %s -I %s -o %s %s"
+ (org-babel-sql-dbstring-saphana
+  dbhost dbport dbinstance dbuser dbpassword database)
+ (org-babel-process-file-name in-file)
+ (org-babel-process-file-name out-file)
+ (or cmdline "")))
 (t (user-error "No support for the %s SQL engine"
engine)
 (with-temp-file in-file
   (insert
@@ -309,7 +332,7 @@ SET COLSEP '|'
  (progn (insert-file-contents-literally out-file) (buffer-string)))
   (with-temp-buffer
  (cond
- ((memq (intern engine) '(dbi mysql postgresql postgres sqsh vertica))
+ ((memq (intern engine) '(dbi mysql postgresql postgres saphana sqsh
vertica))
   ;; Add header row delimiter after column-names header in first line
   (cond
(colnames-p
diff --git a/testing/lisp/test-ob-sql.el b/testing/lisp/test-ob-sql.el
new file mode 100644
index 0..51edd2309
--- /dev/null
+++ b/testing/lisp/test-ob-sql.el
@@ -0,0 +1,382 @@
+;;; test-ob-sql.el --- tests for ob-sql.el
+
+;; Copyright (C) 2021 Robin Joy
+
+;; Author: Robin Joy 
+;; Keywords: lisp
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU 

Turning off all indentation in 9.4.4

2021-02-03 Thread Raoul Comninos
I noticed a change in org since I updated to the latest version when it
comes to automatic indentation. I prefer to turn this off globally,
including for lists. I have tinkered with various settings but have had
no luck so far.
-- 



[PATCH] org.el: Don't clear dynamic block if write function is undefined

2021-02-03 Thread Kyle Meyer
Michael Powe writes:

> Hello,
>
> After logging some clock time, I used the normal key combination, C-u C-c
> C-x C-u to update my timesheet tables, and received this error message.
>
> org-update-dblock: Symbol’s function definition is void:
> org-dblock-write:CLOCKTABLE
[...]
> Well, after recovering from my horror at losing my timesheets for a day's
> work, I was able to track down the problem: the function is case sensitive.
> At some point, (apparently) I fat-fingered a key combo & upcased the mode
> line for two tables. After returning them to l-case, all worked as it
> should.
>
> I dunno - should the function be case insensitive?

I don't think so.  Other libraries and users can define their own
dynamic blocks, and I don't think anything documents that the
org-dblock-write: function must be all lower case.  However, I do
think we could improve the situation by signaling an error if the
function is unknown _before_ clearing the block.

With the below patch, you would have seen

  user-error: Unknown dynamic block type: CLOCKTABLE

and the existing block would have been left as is.  What do you think?

-- >8 --
Subject: [PATCH] org.el: Don't clear dynamic block if write function is
 undefined

* lisp/org.el (org-prepare-dblock): Check whether the block's write
function is defined before clearing the existing contents.
(org-map-dblocks): Relay the message of the caught error to help the
caller figure out what went wrong.

The write function may be undefined because the user unintentionally
modified the dynamic block name or didn't load a library, and deleting
contents in this situation can be alarming.  Instead signal an error
that's hopefully enough for the user to figure out what went wrong.

Reported-by: Michael Powe 
Ref: caf7nvlvrvrmcgmnmhga9+mtue0nav-eh4c17bf4eieryowt...@mail.gmail.com
---
 lisp/org.el | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 5b1443c4e..c9f58c9a5 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9165,6 +9165,8 @@ (defun org-prepare-dblock ()
 (name (org-no-properties (match-string 1)))
 (params (append (list :name name)
 (read (concat "(" (match-string 3) ")")
+(unless (fboundp (intern (concat "org-dblock-write:" name)))
+  (user-error "Unknown dynamic block type: %s" name))
 (save-excursion
   (beginning-of-line 1)
   (skip-chars-forward " \t")
@@ -9189,9 +9191,11 @@ (defun org-map-dblocks ( command)
   (while (re-search-forward org-dblock-start-re nil t)
(goto-char (match-beginning 0))
 (save-excursion
-  (condition-case nil
+  (condition-case err
   (funcall cmd)
-(error (message "Error during update of dynamic block"
+(error
+ (message "Error during update of dynamic block: %s"
+  (error-message-string err)
(unless (re-search-forward org-dblock-end-re nil t)
  (error "Dynamic block not terminated"))
 

base-commit: 369eb2739787b9b24399c803be31e4e793113dd1
-- 
2.30.0





org-contacts problem

2021-02-03 Thread Raoul Comninos


I have set up an org-capture template with the exact example provided in 
org-contacts.el and I get this error:

* %![Error: (void-function org-contacts-template-name)]
:PROPERTIES:
:EMAIL: %![Error: (void-function org-contacts-template-email)]
:PHONE:
:ALIAS:
:NICKNAME:
:IGNORE:
:ICON:
:NOTE:
:ADDRESS:
:BIRTHDAY:
:END:

My code is:

("$" "Contacts" entry (file "~/diary/contacts.org")
 "* %(org-contacts-template-name)
:PROPERTIES:
:EMAIL: %(org-contacts-template-email)
:PHONE:
:ALIAS:
:NICKNAME:
:IGNORE:
:ICON:
:NOTE:
:ADDRESS:
:BIRTHDAY:
:END:")

Can someone perhaps guide me?
-- 



Re: Bug fix attached: org-babel sql postgres, fix hardcode

2021-02-03 Thread Kyle Meyer
Thanks for the patch, and others for the review/feedback.

Alan Light writes:

> Subject: [PATCH 2/2] ob-sql.el: ob-sql.el (org-babel-execute:sql): Use
>  `sql-postgres-program' as   postgresql executable (instead of psql) when
>  defined
>
> * ob-sql.el (org-babel-execute:sql): Use `sql-postgres-program' as
>   postgresql executable (instead of psql) when defined. psql will be the 
> default

I've squash this patch, which as Tom notes is a fixup on top of the
initial one, into the first.  I've also tweaked the commit message a
bit, including adding TINYCHANGE.

https://orgmode.org/worg/org-contribute.html#commit-messages

> ---
>  lisp/org/ob-sql.el | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lisp/org/ob-sql.el b/lisp/org/ob-sql.el
> index 8eca769d02..f46c6c1c6a 100644
> --- a/lisp/org/ob-sql.el
> +++ b/lisp/org/ob-sql.el
> @@ -242,7 +242,7 @@ footer=off -F \"\t\"  %s -f %s -o %s %s"
> (if dbpassword
> (format "PGPASSWORD=%s " dbpassword)
>   "")
> -   (or sql-postgres-program "psql")
> +   (or sql-postgres-program "psql") ;; default 
> is psql

As Tom noted, the use of sql-postgres-program here leads to a
byte-compiler warning.  It probably makes sense to just require sql.el
in the file, but for now I've guarded this with a bound-and-true-p.

Pushed (862048d4c).  Thanks again.



Re: patch: ob-clojure improvements

2021-02-03 Thread Christopher Miles
<#secure method=pgpmime mode=sign>

You're right, seems now need to wait for Ag Ibragimov.

Tim Cross  writes:

OK. As the patch is over 6 months old, it would be good if the original author 
can confirm it is still the latest version and if not, re-send the most recent 
version.

Christopher Miles  writes:

<#!secure method=pgpmime mode=sign>

I checked this thread, seems the original first email of thread contains the 
patch. And it's not merged into Org git yet.

Tim Cross  writes:

OK, will push it up the todo list. Where can I get the latest version of the 
patch or has it been added into the org git repo?

Christopher Miles  writes:

<#!!secure method=pgpmime mode=sign>

Hi, Tim, popup this thread to request review. 

Tim Cross  writes:

I am also interested in ob-clojure and ob-clojurescript improvements. However, 
right now, I'm a tad busy and haven't had time to review what has been done. 
Hopefully, can make some time in the next month or so.

Tim

stardiviner  writes:

agzam.ibragi...@gmail.com writes:

There seems to be a bit of lack of interest for these things. But I'm sure some 
people (myself included) would love to see these kinds of improvements.

Yes, I rarely saw Clojurians in this mailing list.

As I said before, I have never participated in contributing to Org source, some 
guidance would be appreciated.

Org Mode has contribution guide here 
http://orgmode.org/worg/org-contribute.html#patches

Should I keep building it and posting patches? Should I try to go 
incrementally, one small change at a time, or should I just get everything 
working first? If it turns out to be a bigger work, should I ask for permission 
to work in a branch and get access to pushing things to it? Maybe things just 
move slowly, because obviously you can't force maintainers to drop everything 
and concentrate effort to get your things in. Maybe I just have to be a little 
bit more patient?

I think a complete work contains many patches should be better, Also write 
testing if necessary.

I remember ob-clojure.el code are mostly reviewed by Bastien Guerry. I included 
him in Cc: in this email.

On Sat, Jun 20, 2020 at 1:23 AM stardiviner  wrote:

Glad to see your patch, really useful in some cases. Thanks.

Ag Ibragimov  writes:

Hi everyone, here's my attempt to add clojure CLI and babashka support for 
ob-clojure.el - Adds a header parameter to override org-babel-clojure-backend - 
Adds :args param (right now only used for clojure-cli)

I have tested it with these minimal cases:

#+beginsrc clojure :backend clj-cli :args "-Sdeps '{:deps {inflections 
{:mvn/version \"0.13.2\"}}}'" (use 'inflections.core) (plural "word") #+endsrc

#+beginsrc clojure :backend babashka :results output (range 10) #+endsrc

Please let me know what you think. Any advice is appreciated, since I have 
never contributed before. Thank you.

– [ stardiviner ] I try to make every word tell the meaning that I want to 
express.

Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner, Matrix: 
stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
s
-- 
[ stardiviner ]
   I try to make every word tell the meaning that I want to express.

   Blog: https://stardiviner.github.io/
   IRC(freenode): stardiviner, Matrix: stardiviner
   GPG: F09F650D7D674819892591401B5DF1C95AE89AC3