From 30f4c8ccc484de182e68b3eaf38247c2be45dfa0 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Thu, 24 Oct 2019 18:42:32 +0200 Subject: verwende neu --- verwende | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 verwende (limited to 'verwende') diff --git a/verwende b/verwende new file mode 100755 index 0000000..da7cb73 --- /dev/null +++ b/verwende @@ -0,0 +1,45 @@ +#!/bin/sh + +while read -r Barcode; do + [ -z "${Barcode}" ] && break + Barcode=$( + printf '%s' "${Barcode}" \ + | base64 -w0 + ) + infos=$( + for s in 'Schrauben' 'Muttern' 'Unterlegscheiben'; do + printf 'SELECT' + printf '"%s",`%s`.`id`' \ + "${s}" "${s}" + printf ' FROM `%s`' \ + "${s}" + printf ' WHERE `%s`.`Barcode`=FROM_BASE64("%s");\n' \ + "${s}" "${Barcode}" + done \ + | mysql -N --raw --batch \ + | tr '\t' ' ' + ) + if [ -z "${infos}" ]; then + >&2 echo 'Kann ich nicht finden.' + continue + fi + >&2 echo 'Wie viele entnommen?' + read diff + if ! { + printf 'UPDATE `%s`' \ + "${infos% *}" + printf ' SET `%s`.`Anzahl`=`%s`.`Anzahl`-%s' \ + "${infos% *}" \ + "${infos% *}" \ + "${diff}" + printf ' WHERE `%s`.`id`=%s;\n' \ + "${infos% *}" \ + "${infos#* }" + printf 'SELECT ROW_COUNT();\n' + } \ + | mysql -N --raw --batch \ + | grep -qxF '1'; then + >&2 echo 'mysql hat nicht genau eine Zeile geƤndert!' + exit 1 + fi +done -- cgit v1.2.3-70-g09d2