From f81490f13f3bade78dbeb8683e4ea7908fc3fdfd Mon Sep 17 00:00:00 2001
From: Yusei Tahara <yusei@nexedi.com>
Date: Sat, 24 Feb 2018 18:26:23 +0900
Subject: [PATCH] software/erp5, stack/erp5: Add ODBC for MariaDB CONNECT
 engine.

---
 software/erp5/instance-mariadb-schema.json |  8 +++++++-
 stack/erp5/buildout.hash.cfg               |  2 +-
 stack/erp5/instance-mariadb.cfg.in         | 14 +++++++++++++-
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/software/erp5/instance-mariadb-schema.json b/software/erp5/instance-mariadb-schema.json
index 9fc2c00df..9ef8f154d 100644
--- a/software/erp5/instance-mariadb-schema.json
+++ b/software/erp5/instance-mariadb-schema.json
@@ -122,6 +122,12 @@
         }
       },
       "type": "object"
-    }
+    },
+    "odbc-ini": {
+      "description": "Contents of odbc.ini file, see unixodbc document",
+      "default": "",
+      "type": "string"
+    },
+
   }
 }
diff --git a/stack/erp5/buildout.hash.cfg b/stack/erp5/buildout.hash.cfg
index 88508944c..4ca1958c6 100644
--- a/stack/erp5/buildout.hash.cfg
+++ b/stack/erp5/buildout.hash.cfg
@@ -27,7 +27,7 @@ md5sum = 1af531c51f575a1d1362f2ca2d61620d
 
 [template-mariadb]
 filename = instance-mariadb.cfg.in
-md5sum = da7c36ecb490b67360d2afda94b41bff
+md5sum = 705f017e19dc2d1048770284d1d6b31f
 
 [template-kumofs]
 filename = instance-kumofs.cfg.in
diff --git a/stack/erp5/instance-mariadb.cfg.in b/stack/erp5/instance-mariadb.cfg.in
index 62472d869..40638927f 100644
--- a/stack/erp5/instance-mariadb.cfg.in
+++ b/stack/erp5/instance-mariadb.cfg.in
@@ -128,6 +128,7 @@ port = {{ port }}
 socket = ${directory:run}/mariadb.sock
 data-directory = ${directory:mariadb-data}
 tmp-directory = ${directory:tmp}
+etc-directory = ${directory:etc}
 pid-file = ${directory:run}/mariadb.pid
 error-log = ${directory:log}/mariadb_error.log
 slow-query-log = ${directory:log}/mariadb_slowquery.log
@@ -185,11 +186,22 @@ template = inline:#!{{ dash }}
     --skip-name-resolve \
     --datadir='${my-cnf-parameters:data-directory}' \
     --basedir='{{ parameter_dict['mariadb-location'] }}' \
-  && exec '{{ parameter_dict['mariadb-location'] }}/bin/mysqld' \
+  && ODBCSYSINI='${my-cnf-parameters:etc-directory}' exec '{{ parameter_dict['mariadb-location'] }}/bin/mysqld' \
     --defaults-file='${my-cnf:rendered}' \
     "$@"
 rendered = ${directory:services}/mariadb
 
+[odbc-ini-text]
+text = {{ dumps(slapparameter_dict.get('odbc-ini', '').encode('base64')) }}
+
+[{{ section('odbc-ini') }}]
+< = jinja2-template-base
+rendered = ${directory:etc}/odbc.ini
+template = inline:{% raw -%}
+  {{ parameter_dict['text'].decode('base64') }}
+  {%- endraw %}
+context = section parameter_dict odbc-ini-text
+
 [{{ section('logrotate-entry-mariadb') }}]
 < = logrotate-entry-base
 name = mariadb
-- 
2.30.9