2010-09-09 22:18:43 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Setup
|
|
|
|
sql mysql://root@ "drop user 'sqlunittest'@'localhost'"
|
|
|
|
sql mysql://root@ DROP DATABASE sqlunittest;
|
|
|
|
sql mysql://root@ CREATE DATABASE sqlunittest;
|
|
|
|
sql mysql://root@ "CREATE USER 'sqlunittest'@'localhost' IDENTIFIED BY 'CB5A1FFFA5A';"
|
|
|
|
sql mysql://root@ "GRANT ALL PRIVILEGES ON sqlunittest.* TO 'sqlunittest'@'localhost';"
|
|
|
|
|
|
|
|
echo '### Test reading sql from url command line'
|
2010-09-14 16:37:26 +00:00
|
|
|
echo | sql "mysql:///tange?SELECT 'Yes it works' as 'Test reading SQL from command line';"
|
2010-09-09 22:18:43 +00:00
|
|
|
|
|
|
|
echo '### Test reading sql from url command line %-quoting'
|
2010-09-14 16:37:26 +00:00
|
|
|
echo | sql "mysql:///tange?SELECT 'Yes it%20works' as 'Test%20%-quoting%20SQL from command line';"
|
2010-09-09 22:18:43 +00:00
|
|
|
|
|
|
|
echo "### Test .sql/aliases with url on commandline"
|
|
|
|
echo :sqlunittest mysql://sqlunittest:CB5A1FFFA5A@localhost:3306/sqlunittest >> ~/.sql/aliases
|
|
|
|
perl -i -ne '$seen{$_}++ || print' ~/.sql/aliases
|
2010-09-14 16:37:26 +00:00
|
|
|
echo | sql ":sqlunittest?SELECT 'Yes it%20works' as 'Test if .sql/aliases with %-quoting works';"
|
2010-09-09 22:18:43 +00:00
|
|
|
|
|
|
|
echo "### Test cyclic alias .sql/aliases"
|
|
|
|
echo :cyclic :cyclic2 >> ~/.sql/aliases
|
|
|
|
echo :cyclic2 :cyclic3 >> ~/.sql/aliases
|
|
|
|
echo :cyclic3 :cyclic >> ~/.sql/aliases
|
|
|
|
perl -i -ne '$seen{$_}++ || print' ~/.sql/aliases
|
|
|
|
stdout sql ":cyclic3?SELECT 'NO IT DID NOT' as 'Test if :cyclic is found works';"
|
|
|
|
|
2010-09-09 22:37:32 +00:00
|
|
|
echo "### Test alias with statement .sql/aliases"
|
|
|
|
echo ":testselect sqlite:////tmp/file.sqlite?SELECT 'It works' AS 'Test statement in alias';" >> ~/.sql/aliases
|
|
|
|
perl -i -ne '$seen{$_}++ || print' ~/.sql/aliases
|
2010-09-14 16:37:26 +00:00
|
|
|
echo | stdout sql :testselect
|
|
|
|
echo ":testselectmysql mysql://sqlunittest:CB5A1FFFA5A@localhost:3306/sqlunittest?SELECT 'It works' AS 'Test statement in alias';" >> ~/.sql/aliases
|
|
|
|
perl -i -ne '$seen{$_}++ || print' ~/.sql/aliases
|
|
|
|
echo | stdout sql :testselect
|
|
|
|
echo | stdout sql :testselectmysql
|
|
|
|
|
|
|
|
echo "### Test alias followed by SQL as arg"
|
|
|
|
echo ignored | stdout sql :testselect "select 'Arg on cmdline';"
|
|
|
|
|
|
|
|
echo "### Test alias with query followed by SQL as arg"
|
|
|
|
echo ignored | stdout sql :testselect" select 'Query added to alias';" "select 'Arg on cmdline';"
|
|
|
|
|
|
|
|
echo "### Test alias with statement .sql/aliases"
|
|
|
|
echo "select 'Query from stdin';" | sql :testselect" select 'Query added to alias';"
|
|
|
|
echo "select 'Query from stdin';" | sql :testselectmysql" select 'Query added to alias';"
|
2010-09-09 22:37:32 +00:00
|
|
|
|
2010-09-09 22:18:43 +00:00
|
|
|
echo "### Test empty dburl"
|
|
|
|
stdout sql ''
|
|
|
|
|
|
|
|
echo "### Test dburl :"
|
|
|
|
stdout sql ':'
|
|
|
|
|
2010-09-14 21:25:53 +00:00
|
|
|
echo "### Test oracle with multiple arguments on the command line"
|
|
|
|
echo ":oraunittest oracle://hr:hr@/xe" >> ~/.sql/aliases
|
|
|
|
perl -i -ne '$seen{$_}++ || print' ~/.sql/aliases
|
|
|
|
sql :oraunittest "WHENEVER SQLERROR EXIT FAILURE" "SELECT 'arg2' FROM DUAL;" "SELECT 'arg3' FROM DUAL;"
|
2010-09-22 21:54:42 +00:00
|
|
|
|
|
|
|
echo "### Test oracle with \n arguments on the command line"
|
|
|
|
sql :oraunittest 'select 1 from dual;\nselect 2 from dual;\x0aselect 3 from dual;'
|