2010-09-01 13:26:45 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-12-26 22:29:28 +00:00
|
|
|
# SPDX-FileCopyrightText: 2021-2022 Ole Tange, http://ole.tange.dk and Free Software and Foundation, Inc.
|
2021-03-22 20:16:35 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2016-08-03 21:45:13 +00:00
|
|
|
exec 2>&1
|
2012-10-22 06:32:39 +00:00
|
|
|
|
2020-08-29 20:12:46 +00:00
|
|
|
## 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';"
|
2012-10-22 06:32:39 +00:00
|
|
|
|
2020-08-29 20:12:46 +00:00
|
|
|
MYSQL_TEST_DBURL=mysql://tange:tange@/
|
2010-09-01 13:26:45 +00:00
|
|
|
|
|
|
|
echo '### Test of #! -Y with file as input'
|
|
|
|
cat >/tmp/shebang <<EOF
|
2012-10-22 06:32:39 +00:00
|
|
|
#!/usr/local/bin/sql -Y $MYSQL_TEST_DBURL
|
2010-09-01 13:26:45 +00:00
|
|
|
|
|
|
|
SELECT 'Yes it does' AS 'Testing if -Y works';
|
|
|
|
EOF
|
|
|
|
chmod 755 /tmp/shebang
|
|
|
|
/tmp/shebang
|
|
|
|
|
|
|
|
echo '### Test of #! --shebang with file as input'
|
|
|
|
cat >/tmp/shebang <<EOF
|
2012-10-22 06:32:39 +00:00
|
|
|
#!/usr/local/bin/sql --shebang $MYSQL_TEST_DBURL
|
2010-09-01 13:26:45 +00:00
|
|
|
|
|
|
|
SELECT 'Yes it does' AS 'Testing if --shebang works';
|
|
|
|
EOF
|
|
|
|
chmod 755 /tmp/shebang
|
|
|
|
/tmp/shebang
|
|
|
|
|
|
|
|
echo '### Test reading sql on command line'
|
2012-10-22 06:32:39 +00:00
|
|
|
sql $MYSQL_TEST_DBURL "SELECT 'Yes it does' as 'Test reading SQL from command line';"
|
2010-09-01 13:26:45 +00:00
|
|
|
|
|
|
|
echo '### Test reading sql from file'
|
|
|
|
cat >/tmp/unittest.sql <<EOF
|
|
|
|
DROP TABLE IF EXISTS unittest;
|
|
|
|
CREATE TABLE unittest (
|
|
|
|
id INT,
|
|
|
|
data VARCHAR(100)
|
|
|
|
);
|
|
|
|
INSERT INTO unittest VALUES (1,'abc');
|
|
|
|
INSERT INTO unittest VALUES (3,'def');
|
|
|
|
SELECT 'Yes it does' as 'Test reading SQL from file works';
|
|
|
|
EOF
|
2012-10-22 06:32:39 +00:00
|
|
|
sql $MYSQL_TEST_DBURL/sqlunittest </tmp/unittest.sql
|
2010-09-01 13:26:45 +00:00
|
|
|
|
|
|
|
echo '### Test dburl with username password host port'
|
2020-08-29 20:12:46 +00:00
|
|
|
sql mysql://tange:tange@localhost:3306/tange </tmp/unittest.sql
|
2010-09-01 13:26:45 +00:00
|
|
|
|
2010-09-07 23:43:11 +00:00
|
|
|
echo "### Test .sql/aliases"
|
2012-10-22 06:32:39 +00:00
|
|
|
mkdir -p ~/.sql
|
2010-09-07 23:43:11 +00:00
|
|
|
echo :sqlunittest mysql://sqlunittest:CB5A1FFFA5A@localhost:3306/sqlunittest >> ~/.sql/aliases
|
2010-09-09 22:18:43 +00:00
|
|
|
perl -i -ne '$seen{$_}++ || print' ~/.sql/aliases
|
2010-09-07 23:43:11 +00:00
|
|
|
sql :sqlunittest "SELECT 'Yes it does' as 'Test if .sql/aliases works';"
|
2010-09-01 13:26:45 +00:00
|
|
|
|
2011-03-09 15:23:53 +00:00
|
|
|
echo "### Test sql:sql::alias"
|
|
|
|
sql sql:sql::sqlunittest "SELECT 'Yes it works' as 'Test sql:sql::alias';"
|
|
|
|
|
2010-09-01 13:26:45 +00:00
|
|
|
echo "### Test --noheaders --no-headers -n"
|
2010-09-05 10:22:08 +00:00
|
|
|
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}
|
2010-09-01 13:26:45 +00:00
|
|
|
|
|
|
|
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";
|
2012-10-22 06:32:39 +00:00
|
|
|
sql --html $MYSQL_TEST_DBURL/sqlunittest 'select * from unittest'
|
2010-09-01 13:26:45 +00:00
|
|
|
echo
|
|
|
|
|
|
|
|
echo "### Test --show-processlist|proclist|listproc";
|
2010-09-07 23:43:11 +00:00
|
|
|
sql --show-processlist :sqlunittest | wc -lw
|
|
|
|
sql --proclist :sqlunittest | wc -lw
|
|
|
|
sql --listproc :sqlunittest | wc -lw
|
2010-09-01 13:26:45 +00:00
|
|
|
|
|
|
|
echo "### Test --db-size --dbsize";
|
2020-10-22 19:47:01 +00:00
|
|
|
sql --dbsize :sqlunittest | wc -w
|
|
|
|
sql --db-size :sqlunittest | wc -w
|
2010-09-01 13:26:45 +00:00
|
|
|
|
|
|
|
echo "### Test --table-size --tablesize"
|
2020-10-22 19:47:01 +00:00
|
|
|
sql --showtables :sqlunittest | grep TBL | parallel sql :sqlunittest drop table
|
2010-09-01 13:26:45 +00:00
|
|
|
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
|