#!/bin/bash # SPDX-FileCopyrightText: 2021 Ole Tange, http://ole.tange.dk and Free Software and Foundation, Inc. # # SPDX-License-Identifier: GPL-3.0-or-later exec 2>&1 ## Setup # mysqlrootpass=${mysqlrootpass:-M-b+Ydjq4ejT4E} # MYSQL_ADMIN_DBURL=mysql://root:$mysqlrootpass@/mysql # sql $MYSQL_ADMIN_DBURL "drop user 'sqlunittest'@'localhost'" # sql $MYSQL_ADMIN_DBURL DROP DATABASE sqlunittest; # sql $MYSQL_ADMIN_DBURL CREATE DATABASE sqlunittest; # sql $MYSQL_ADMIN_DBURL "CREATE USER 'sqlunittest'@'localhost' IDENTIFIED BY 'CB5A1FFFA5A';" # sql $MYSQL_ADMIN_DBURL "GRANT ALL PRIVILEGES ON sqlunittest.* TO 'sqlunittest'@'localhost';" MYSQL_TEST_DBURL=mysql://tange:tange@/ echo '### Test of #! -Y with file as input' cat >/tmp/shebang </tmp/shebang </tmp/unittest.sql <> ~/.sql/aliases perl -i -ne '$seen{$_}++ || print' ~/.sql/aliases sql :sqlunittest "SELECT 'Yes it does' as 'Test if .sql/aliases works';" echo "### Test sql:sql::alias" sql sql:sql::sqlunittest "SELECT 'Yes it works' as 'Test sql:sql::alias';" echo "### Test --noheaders --no-headers -n" sql -n :sqlunittest 'select * from unittest order by id' \ | parallel -k --colsep '\t' echo {2} {1} sql --noheaders :sqlunittest 'select * from unittest order by id' \ | parallel -k --colsep '\t' echo {2} {1} sql --no-headers :sqlunittest 'select * from unittest order by id' \ | parallel -k --colsep '\t' echo {2} {1} echo "### Test --sep -s"; sql --no-headers -s : pg:/// 'select 1,2' | parallel --colsep ':' echo {2} {1} sql --no-headers --sep : pg:/// 'select 1,2' | parallel --colsep ':' echo {2} {1} echo "### Test --passthrough -p"; sql -p -H :sqlunittest 'select * from unittest' echo sql --passthrough -H :sqlunittest 'select * from unittest' echo echo "### Test --html"; sql --html $MYSQL_TEST_DBURL/sqlunittest 'select * from unittest' echo echo "### Test --show-processlist|proclist|listproc"; sql --show-processlist :sqlunittest | wc -lw sql --proclist :sqlunittest | wc -lw sql --listproc :sqlunittest | wc -lw echo "### Test --db-size --dbsize"; sql --dbsize :sqlunittest | wc -w sql --db-size :sqlunittest | wc -w echo "### Test --table-size --tablesize" sql --showtables :sqlunittest | grep TBL | parallel sql :sqlunittest drop table sql --tablesize :sqlunittest | wc -l sql --table-size :sqlunittest | wc -l echo "### Test --debug" sql --debug :sqlunittest "SELECT 'Yes it does' as 'Test if --debug works';" echo "### Test --version -V" sql --version | wc sql -V | wc echo "### Test -r" stdout sql -r --debug pg://nongood@127.0.0.3:2227/ "SELECT 'This should fail 3 times';" echo "### Test --retries=s" stdout sql --retries=4 --debug pg://nongood@127.0.0.3:2227/ "SELECT 'This should fail 4 times';" echo "### Test --help -h" sql --help sql -h