diff options
author | Ramón M. Gómez <ramongomez@us.es> | 2019-11-11 17:38:05 +0100 |
---|---|---|
committer | Ramón M. Gómez <ramongomez@us.es> | 2019-11-11 17:38:05 +0100 |
commit | e93dfe5f60e86d08b5bb4c64d1ce01f2fd1be4ae (patch) | |
tree | 1f7289908d9f318436921c35e5c786f06eccbade | |
parent | 83f20d1889a73f0088f61b4014c80fb4248a21be (diff) |
#839: Use global function to execute commands in the database.
-rwxr-xr-x | server/lib/checkrest | 15 | ||||
-rwxr-xr-x | server/lib/ogfunctions.sh | 17 |
2 files changed, 17 insertions, 15 deletions
diff --git a/server/lib/checkrest b/server/lib/checkrest index 34f44ed1..3db161f5 100755 --- a/server/lib/checkrest +++ b/server/lib/checkrest @@ -44,21 +44,6 @@ function route () { printf "%-40s: %s\n" "- $METHOD $ROUTE" "$STATUS" } -# Execute database operation. -function dbexec () { - MYCNF=$(mktemp) - trap "rm -f $MYCNF" 0 1 2 3 6 9 15 - touch $MYCNF - chmod 600 $MYCNF - cat << EOT > $MYCNF -[client] -user=$USUARIO -password=$PASSWORD -EOT - mysql --defaults-extra-file="$MYCNF" -D "$CATALOG" -s -N -e "$1" || \ - raiseError access "Cannot access the databse" -} - # Delete test data from the database. function deletedata () { # Delete test data, if exists. diff --git a/server/lib/ogfunctions.sh b/server/lib/ogfunctions.sh index 34b2ab7b..4b61166b 100755 --- a/server/lib/ogfunctions.sh +++ b/server/lib/ogfunctions.sh @@ -68,6 +68,22 @@ function stop() { _service stop "$1" } +# Execute database operation. +function dbexec () { + MYCNF=$(mktemp) + trap "rm -f $MYCNF" 0 1 2 3 6 9 15 + touch $MYCNF + chmod 600 $MYCNF + cat << EOT > $MYCNF +[client] +user=$USUARIO +password=$PASSWORD +EOT + mysql --defaults-extra-file="$MYCNF" -D "$CATALOG" -s -N -e "$1" || \ + raiseError access "Cannot access the databse" + rm -f "$MYCNF" +} + ### Meta-functions and private functions. @@ -94,3 +110,4 @@ function _service() { raiseError notfound "Service $SERVICE" fi } + |