From 6a3fd4ca52b6e799bd2dc250b28d994e1ac8cb65 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Fri, 1 Dec 2017 12:23:30 +0100 Subject: bin/mysql-functions: a start --- bin/mysql-functions | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 bin/mysql-functions diff --git a/bin/mysql-functions b/bin/mysql-functions new file mode 100755 index 0000000..33f5d6d --- /dev/null +++ b/bin/mysql-functions @@ -0,0 +1,44 @@ +#!/bin/sh + +# contains functions used to access mysql db + +# shellcheck disable=SC2039 + +mysql_command='mysql buildmaster -e' + +# add_package_source $pkgbase $pkgver $pkgrel $git_revision $mod_git_revision $upstream_package_repository + +# shellcheck disable=SC2016,SC2086 +add_package_source() { + local names='pkgbase pkgver pkgrel git_revision mod_git_revision upstream_package_repository' + local values; + for _ in ${names}; do + values="${values}$( + printf '%s' "$1" | \ + base64 -w0 + ) " + shift + done + values="${values% }" + + ${mysql_command} "$( + printf 'INSERT IGNORE INTO package_sources' + { + printf ' (' + printf '`%s`, ' ${names} + printf ') SELECT' + printf ' from_base64("%s"), ' ${values% *} + printf ' `upstream_repositories`.`id`' + printf ' FROM `upstream_repositories`' + printf ' WHERE `upstream_repositories`.`name` = from_base64("%s");' \ + "${values##* }" + } | \ + sed 's|, )|)|g' + )" + + ${mysql_command} "$( + printf 'SELECT * FROM package_sources' + printf ' LEFT JOIN upstream_repositories' + printf ' ON package_sources.upstream_package_repository = upstream_repositories.id;' + )" +} -- cgit v1.2.3-70-g09d2