summaryrefslogtreecommitdiff
path: root/verwende
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-10-24 18:42:32 +0200
committerErich Eckner <git@eckner.net>2019-10-24 18:42:32 +0200
commit30f4c8ccc484de182e68b3eaf38247c2be45dfa0 (patch)
tree16cf958ca6599375b277f12610f0230286fcdada /verwende
parent3b94c7504d2b6927b081e3dd58e854a7a1224345 (diff)
downloadSchraubendatenbank-30f4c8ccc484de182e68b3eaf38247c2be45dfa0.tar.xz
verwende neuHEADmaster
Diffstat (limited to 'verwende')
-rwxr-xr-xverwende45
1 files changed, 45 insertions, 0 deletions
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