summaryrefslogtreecommitdiff
path: root/lib/mysql-functions
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mysql-functions')
-rwxr-xr-xlib/mysql-functions27
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/mysql-functions b/lib/mysql-functions
index 0c633c8..af2c3ba 100755
--- a/lib/mysql-functions
+++ b/lib/mysql-functions
@@ -2,7 +2,7 @@
# contains functions used to access mysql db
-# shellcheck disable=SC2016,SC2039,SC2119,SC2120
+# shellcheck disable=SC2016,SC2039,SC2119,SC2120,SC3043
if [ -z "${base_dir}" ]; then
# just to make shellcheck happy
@@ -35,7 +35,7 @@ mysql_run_query() {
local number
file_name_extra=''
- if [ "x$1" = 'xunimportant' ]; then
+ if [ "$1" = 'unimportant' ]; then
shift
file_name_extra='unimportant_'
elif [ -s "${work_dir}/build-master-sanity" ]; then
@@ -47,7 +47,7 @@ mysql_run_query() {
query_stdout="${query_stdin%.stdin}.stdout"
query_stderr="${query_stdin%.stdin}.stderr"
cat > "${query_stdin}"
- for _ in {1..10}; do
+ for _ in $(seq 10); do
if [ -f "${query_stdout}" ]; then
wait_some_time 10 10
fi
@@ -78,7 +78,7 @@ mysql_run_query() {
# a present query_file means there was an error
if [ -f "${query_stdin}" ]; then
>&2 printf 'I (%s) could not complete a mysql query:\n' \
- "$(hostname)"
+ "$(uname -n)"
>&2 sed 's/^/mysql< /' "${query_stdin}"
>&2 sed 's/^/mysql>2 /' "${query_stderr}"
files="${query_stdin} ${query_stdout} ${query_stderr}$(
@@ -221,7 +221,8 @@ mysql_generate_package_metadata() {
mod_git_revision="$4"
repository="$5"
- if [[ "${current_repository_id}" = *[!0-9]* ]]; then
+ if printf '%s\n' "${current_repository_id}" \
+ | grep -q '[^0-9]'; then
>&2 printf 'mysql_generate_package_metadata(): invalid current_repository_id="%s".\n' \
"${current_repository_id}"
exit 2
@@ -898,7 +899,7 @@ mysql_cleanup() {
local operator
if [ "$#" = '0' ]; then
operator='DELETE'
- elif [ "$#" = '1' ] && [ "x$1" = 'xdry' ]; then
+ elif [ "$#" = '1' ] && [ "$1" = 'dry' ]; then
operator='SELECT COUNT(1)'
else
>&2 echo 'Unknown parameter'
@@ -1440,6 +1441,7 @@ mysql_join_dependencies_install_target_providers_with_versions() {
# - ids of compressions -> $compression_ids__$compression
# - $package_compression_suffix_regex
mysql_retrieve_static_information() {
+ local found_something
eval "$(
{
printf 'SELECT CONCAT('
@@ -1513,9 +1515,16 @@ mysql_retrieve_static_information() {
printf ') SEPARATOR "\\\\|"),'
printf '"\\""'
printf ') FROM `compressions`;\n'
- } | \
- mysql_run_query
+ } \
+ | sed '
+ s@^\(SELECT \)\(.*\)$@SELECT "found_something=false;"; \1"found_something=true; ",\2 SELECT "if ! ${found_something}; then >\&2 echo \\"Some variable was not found in the database.\\"; exit 1; fi;";@
+ ' \
+ | mysql_run_query
)"
+ if ! ${found_something}; then
+ >&2 echo 'No variables were found in the database.'
+ exit 1
+ fi
}
# mysql_query_and_delete_unneeded_binary_packages
@@ -1550,7 +1559,7 @@ mysql_sort_versions() {
( # new shell is intentional
tmp_file=$(mktemp 'tmp.mysql_sort_versions.XXXXXXXXXX' --tmpdir)
trap 'rm "${tmp_file}"' EXIT
- if [ "x$1" != 'x-f' ] && \
+ if [ "$1" != '-f' ] && \
{
printf 'SELECT'
printf ' COUNT(1)'