32 lines
897 B
Bash
Executable File
32 lines
897 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
if [ "$#" -ne 1 ]; then
|
|
echo "Usage: query.sh <mm:ss>"
|
|
exit 1
|
|
fi
|
|
|
|
TIME=$1
|
|
shift
|
|
|
|
DB="db/rowing.sqlite3"
|
|
|
|
cat<<EOF | sqlite3 "${DB}"
|
|
SELECT
|
|
CASE
|
|
WHEN (CAST(REPLACE('${TIME}', ':', '') AS INTEGER) < (SELECT REPLACE(MIN(min_time), ':', '') FROM rowing))
|
|
THEN 'You are off the charts too fast'
|
|
WHEN (CAST(REPLACE('${TIME}', ':', '') AS INTEGER) > (SELECT REPLACE(MAX(max_time), ':', '') FROM rowing))
|
|
THEN 'You are off the charts too slow'
|
|
ELSE
|
|
'${TIME} is ' ||
|
|
CASE
|
|
WHEN SUBSTR(LOWER(word), 1, 1) IN ('a', 'e', 'i', 'o', 'u') THEN 'an'
|
|
ELSE 'a'
|
|
END || ' ' || word || ' time'
|
|
END AS message
|
|
FROM (
|
|
SELECT rating AS word FROM rowing WHERE '${TIME}' BETWEEN min_time AND max_time
|
|
UNION ALL SELECT 1 AS word LIMIT 1 -- dummy selection to make sure the out-of-bounds messages get shown
|
|
);
|
|
EOF
|