-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
sql_test.sh
executable file
·72 lines (66 loc) · 1.76 KB
/
sql_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
MYSQL=$1
if [ -z "$MYSQL" ]
then
echo "Syntax: $0 mysql_connection "
echo "Where 'mysql_connection is your client invocation"
echo "Examples:"
echo " mysql # (when using \$HOME/.my.cnf)"
echo " 'mysql -u something -psomepass -P3307'"
echo " 'mysql --defaults-file=/some/path/my.cnf'"
echo " \$HOME/sandboxes/msb_5_7_9/use"
echo ""
exit 1
fi
EXPECTED=(
departments:9:3737256214
dept_emp:331603:1015881734
dept_manager:24:2275236704
employees:300024:610052939
salaries:2844047:4273816835
titles:443308:1842528371
)
function get_expected
{
table=$1
field=$2
for E in ${EXPECTED[*]}
do
t=$(echo $E | tr ':' ' ' | awk '{print $1}')
count=$(echo $E | tr ':' ' ' | awk '{print $2}')
crc=$(echo $E | tr ':' ' ' | awk '{print $3}')
if [ "$t" == "$table" ]
then
if [ "$field" == "count" ]
then
echo $count
else
echo $crc
fi
return
fi
done
}
printf "%-15s %-10s %-15s \n" table count crc
echo '--------------- ---------- ---------------'
for T in $($MYSQL -BN -e 'show tables from employees')
do
CRC_TEXT=$($MYSQL -BN -e "checksum table $T" employees)
COUNT=$($MYSQL -BN -e "select count(*) from $T" employees)
CRC=$(echo $CRC_TEXT | awk '{print $2}')
expected_crc=$(get_expected $T crc)
expected_count=$(get_expected $T count)
if [ "$expected_count" == "$COUNT" ]
then
COUNT_RESULT=OK
else
COUNT_RESULT=DIFFERS
fi
if [ "$expected_crc" == "$CRC" ]
then
CRC_RESULT=OK
else
CRC_RESULT=DIFFERS
fi
printf "%-15s %'10d %'15d (%-7s %-7s)\n" $T $COUNT $CRC $COUNT_RESULT $CRC_RESULT
done