From b1c5d47ca98735d6f1780572dab4c338254aadb3 Mon Sep 17 00:00:00 2001
From: Daniel <daniel@harvey>
Date: Thu, 26 Mar 2020 18:55:21 +0100
Subject: [PATCH] FIX: Load definitions first.

---
 utils/helpers.sh               | 26 ++++++++++++++++++--------
 utils/update_sql_procedures.sh |  6 ++++++
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/utils/helpers.sh b/utils/helpers.sh
index 5762301..90115af 100644
--- a/utils/helpers.sh
+++ b/utils/helpers.sh
@@ -2,7 +2,7 @@
 #
 # Copyright (C) 2018 Research Group Biomedical Physics,
 # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
-# Copyright 2019 Daniel Hornung
+# Copyright 2019, 2020 Daniel Hornung
 # Copyright 2020 Henrik tom Wörden, IndiScale GmbH
 #
 # This program is free software: you can redistribute it and/or modify
@@ -19,16 +19,26 @@
 # along with this program. If not, see <https://www.gnu.org/licenses/>.
 
 
+
+###############################################################################
+#                         Helper function definitions                         #
+###############################################################################
+
+# When sourcing this file, the following variables must be set:
+#
+# MYSQL_CMD : source $UTILSPATH/load_settings.sh
+
+
+
 function mysql_execute {
 	  #TODO is it meaningful that here always the database user is used???
 	  set +e
-    env
-	$MYSQL_CMD $(get_db_args) -e "$1"
-	ret=${PIPESTATUS[0]}
-	if [ "$ret" -ne 0 ]; then
-		failure "MYSQL ERROR"
-	fi
-	set -e
+	  $MYSQL_CMD $(get_db_args) -e "$1"
+	  ret=${PIPESTATUS[0]}
+	  if [ "$ret" -ne 0 ]; then
+		    failure "MYSQL ERROR"
+	  fi
+	  set -e
 }
 
 function get_mysql_args {
diff --git a/utils/update_sql_procedures.sh b/utils/update_sql_procedures.sh
index 73f6bac..e363a7d 100755
--- a/utils/update_sql_procedures.sh
+++ b/utils/update_sql_procedures.sh
@@ -24,7 +24,13 @@
 
 # Updates all SQL procedures
 
+if [ -z "$UTILSPATH" ]; then
+    UTILSPATH=$(realpath "$(dirname $0)")
+    export UTILSPATH
+fi
+
 source $UTILSPATH/helpers.sh
+source $UTILSPATH/load_settings.sh
 
 echo -n "updating rules ... "
 set -e
-- 
GitLab