mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-11-22 22:17:54 +00:00
sql: RFC3986 calls the statement part a query. Let's do that, too.
sql: test sql02 and results.
This commit is contained in:
parent
944a4fdd4f
commit
e63e97916c
34
src/sql
34
src/sql
|
@ -149,21 +149,21 @@ For this to work B<--shebang> or B<-Y> must be set as the first option.
|
||||||
=head1 DBURL
|
=head1 DBURL
|
||||||
|
|
||||||
A DBURL has the following syntax:
|
A DBURL has the following syntax:
|
||||||
[sql:]vendor://[user[:password]@][host][:port]/[database][?sqlstatement]
|
[sql:]vendor://[user[:password]@][host][:port]/[database][?sqlquery]
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
mysql://user:pa55w0rd@mysqlserver/database
|
mysql://user:pa55w0rd@mysqlserver/database
|
||||||
sql:oracle://scott:tiger@oracleserver/xe
|
sql:oracle://scott:tiger@oracleserver/xe
|
||||||
postgresql://user:pa55w0rd@pg.example.com/db
|
postgresql://user:pa55w0rd@pg.example.com/db
|
||||||
pg:///
|
pg:///
|
||||||
sqlite2:////tmp/db.sqlite?select * from foo;
|
sql:sqlite2:////tmp/db.sqlite?select * from foo;
|
||||||
sqlite3:///../db.sqlite3?select%20*%20from%20foo;
|
sqlite3:///../db.sqlite3?select%20*%20from%20foo;
|
||||||
|
|
||||||
Currently supported vendors: MySQL (mysql), MySQL with SSL (mysqls,
|
Currently supported vendors: MySQL (mysql), MySQL with SSL (mysqls,
|
||||||
mysqlssl), Oracle (oracle, ora), PostgreSQL (postgresql, pg, pgsql,
|
mysqlssl), Oracle (oracle, ora), PostgreSQL (postgresql, pg, pgsql,
|
||||||
postgres), PostgreSQL with SSL (postgresqlssl, pgs, pgsqlssl,
|
postgres), PostgreSQL with SSL (postgresqlssl, pgs, pgsqlssl,
|
||||||
postgresssl, pgssl, postgresqls, pgsqls, postgress), SQLite (sqlite2,
|
postgresssl, pgssl, postgresqls, pgsqls, postgress), SQLite2 (sqlite,
|
||||||
sqlite3).
|
sqlite2), SQLite3 (sqlite3).
|
||||||
|
|
||||||
Aliases must start with ':' and are read from
|
Aliases must start with ':' and are read from
|
||||||
/etc/sql/aliases and ~/.sql/aliases. The user's own
|
/etc/sql/aliases and ~/.sql/aliases. The user's own
|
||||||
|
@ -181,8 +181,8 @@ Example of aliases:
|
||||||
:m :myalias4
|
:m :myalias4
|
||||||
# the sortest alias possible
|
# the sortest alias possible
|
||||||
: sqlite2:////tmp/mydefault.sqlite
|
: sqlite2:////tmp/mydefault.sqlite
|
||||||
# Including an SQL statement
|
# Including an SQL query
|
||||||
:stm sqlite:////tmp/file.sqlite?select * from foo;
|
:query sqlite:////tmp/file.sqlite?select * from foo;
|
||||||
|
|
||||||
=head1 EXAMPLES
|
=head1 EXAMPLES
|
||||||
|
|
||||||
|
@ -333,9 +333,11 @@ A copy of the full license is included in the file as cc-by-sa.txt.
|
||||||
=head1 DEPENDENCIES
|
=head1 DEPENDENCIES
|
||||||
|
|
||||||
GNU B<sql> uses Perl. If B<mysql> is installed, MySQL dburls will
|
GNU B<sql> uses Perl. If B<mysql> is installed, MySQL dburls will
|
||||||
work. If B<psql> is installed, PostgreSQL dburls will work. If
|
work. If B<psql> is installed, PostgreSQL dburls will work. If
|
||||||
B<sqlplus> is installed, Oracle dburls will work. If B<rlwrap> is
|
B<sqlite> is installed, SQLite2 dburls will work. If B<sqlite3> is
|
||||||
installed, GNU B<sql> will have a command history for Oracle.
|
installed, SQLite3 dburls will work. If B<sqlplus> is installed,
|
||||||
|
Oracle dburls will work. If B<rlwrap> is installed, GNU B<sql> will
|
||||||
|
have a command history for Oracle.
|
||||||
|
|
||||||
|
|
||||||
=head1 FILES
|
=head1 FILES
|
||||||
|
@ -347,7 +349,7 @@ installed, GNU B<sql> will have a command history for Oracle.
|
||||||
|
|
||||||
=head1 SEE ALSO
|
=head1 SEE ALSO
|
||||||
|
|
||||||
B<mysql>(1), B<psql>(1), B<sqlplus>(1), B<rlwrap>(1)
|
B<mysql>(1), B<psql>(1), B<rlwrap>(1), B<sqlite>(1), B<sqlite3>(1), B<sqlplus>(1)
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
@ -399,8 +401,8 @@ if(defined $::opt_tablesize) {
|
||||||
unshift @ARGV, tablesize($database_driver,%dburl);
|
unshift @ARGV, tablesize($database_driver,%dburl);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($dburl{'statement'}) {
|
if($dburl{'query'}) {
|
||||||
unshift @ARGV,$dburl{'statement'};
|
unshift @ARGV,$dburl{'query'};
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -779,7 +781,7 @@ sub check_permissions {
|
||||||
sub parse_dburl {
|
sub parse_dburl {
|
||||||
my $url = shift;
|
my $url = shift;
|
||||||
my %options = ();
|
my %options = ();
|
||||||
# sql:mysql://[[user][:password]@][host][:port]/[database[?sql statement]]
|
# sql:mysql://[[user][:password]@][host][:port]/[database[?sql query]]
|
||||||
|
|
||||||
if($url=~m!(?:sql:)? # You can prefix with 'sql:'
|
if($url=~m!(?:sql:)? # You can prefix with 'sql:'
|
||||||
((?:oracle|ora|mysql|pg|postgres|postgresql)(?:s|ssl|)|
|
((?:oracle|ora|mysql|pg|postgres|postgresql)(?:s|ssl|)|
|
||||||
|
@ -801,7 +803,7 @@ sub parse_dburl {
|
||||||
)?
|
)?
|
||||||
(?:
|
(?:
|
||||||
\?
|
\?
|
||||||
(.*)? # Statement ($7)
|
(.*)? # Query ($7)
|
||||||
)?
|
)?
|
||||||
!x) {
|
!x) {
|
||||||
$options{databasedriver} = undef_if_empty($1);
|
$options{databasedriver} = undef_if_empty($1);
|
||||||
|
@ -810,12 +812,12 @@ sub parse_dburl {
|
||||||
$options{host} = undef_if_empty($4);
|
$options{host} = undef_if_empty($4);
|
||||||
$options{port} = undef_if_empty($5);
|
$options{port} = undef_if_empty($5);
|
||||||
$options{database} = undef_if_empty($6);
|
$options{database} = undef_if_empty($6);
|
||||||
$options{statement} = undef_if_empty(uri_unescape($7));
|
$options{query} = undef_if_empty(uri_unescape($7));
|
||||||
debug("dburl $url\n");
|
debug("dburl $url\n");
|
||||||
debug("databasedriver ",$options{databasedriver}, " user ", $options{user},
|
debug("databasedriver ",$options{databasedriver}, " user ", $options{user},
|
||||||
" password ", $options{password}, " host ", $options{host},
|
" password ", $options{password}, " host ", $options{host},
|
||||||
" port ", $options{port}, " database ", $options{database},
|
" port ", $options{port}, " database ", $options{database},
|
||||||
" statement ",$options{statement}, "\n");
|
" query ",$options{query}, "\n");
|
||||||
} else {
|
} else {
|
||||||
Usage("$url is not a valid DBURL");
|
Usage("$url is not a valid DBURL");
|
||||||
exit -1;
|
exit -1;
|
||||||
|
|
26
unittest/tests-to-run/sql02.sh
Normal file
26
unittest/tests-to-run/sql02.sh
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cd /tmp
|
||||||
|
echo '### Test of sqlite'
|
||||||
|
for CMDSQL in sqlite sqlite3 ; do
|
||||||
|
echo "Current command: $CMDSQL"
|
||||||
|
rm -f sqltest.$CMDSQL
|
||||||
|
# create database & table
|
||||||
|
sql $CMDSQL:///sqltest.$CMDSQL "CREATE TABLE foo(n INT, t TEXT);"
|
||||||
|
file sqltest.$CMDSQL
|
||||||
|
sql $CMDSQL:///sqltest.$CMDSQL "INSERT INTO foo VALUES(1,'Line 1');"
|
||||||
|
sql $CMDSQL:///sqltest.$CMDSQL "INSERT INTO foo VALUES(2,'Line 2');"
|
||||||
|
sql $CMDSQL:///sqltest.$CMDSQL "SELECT * FROM foo;"
|
||||||
|
sql -n $CMDSQL:///sqltest.$CMDSQL "SELECT * FROM foo;"
|
||||||
|
sql -s '.' $CMDSQL:///sqltest.$CMDSQL "SELECT * FROM foo;"
|
||||||
|
sql -n -s '.' $CMDSQL:///sqltest.$CMDSQL "SELECT * FROM foo;"
|
||||||
|
sql -s '' $CMDSQL:///sqltest.$CMDSQL "SELECT * FROM foo;"
|
||||||
|
sql -s ' ' $CMDSQL:///sqltest.$CMDSQL "SELECT * FROM foo;"
|
||||||
|
sql --html $CMDSQL:///sqltest.$CMDSQL "SELECT * FROM foo;"
|
||||||
|
sql -n --html $CMDSQL:///sqltest.$CMDSQL "SELECT * FROM foo;"
|
||||||
|
sql --dbsize $CMDSQL:///sqltest.$CMDSQL
|
||||||
|
sql $CMDSQL:///sqltest.$CMDSQL "DROP TABLE foo;"
|
||||||
|
sql --dbsize $CMDSQL:///sqltest.$CMDSQL
|
||||||
|
rm -f sqltest.$CMDSQL
|
||||||
|
done
|
||||||
|
|
73
unittest/wanted-results/sql02
Normal file
73
unittest/wanted-results/sql02
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
### Test of sqlite
|
||||||
|
Current command: sqlite
|
||||||
|
sqltest.sqlite: SQLite 2.x database
|
||||||
|
n|t
|
||||||
|
1|Line 1
|
||||||
|
2|Line 2
|
||||||
|
1|Line 1
|
||||||
|
2|Line 2
|
||||||
|
n.t
|
||||||
|
1.Line 1
|
||||||
|
2.Line 2
|
||||||
|
1.Line 1
|
||||||
|
2.Line 2
|
||||||
|
nt
|
||||||
|
1Line 1
|
||||||
|
2Line 2
|
||||||
|
n t
|
||||||
|
1 Line 1
|
||||||
|
2 Line 2
|
||||||
|
<TR><TH>n</TH><TH>t</TH></TR>
|
||||||
|
<TR><TD>1</TD>
|
||||||
|
<TD>Line 1</TD>
|
||||||
|
</TR>
|
||||||
|
<TR><TD>2</TD>
|
||||||
|
<TD>Line 2</TD>
|
||||||
|
</TR>
|
||||||
|
<TR><TD>1</TD>
|
||||||
|
<TD>Line 1</TD>
|
||||||
|
</TR>
|
||||||
|
<TR><TD>2</TD>
|
||||||
|
<TD>Line 2</TD>
|
||||||
|
</TR>
|
||||||
|
bytes
|
||||||
|
3072
|
||||||
|
bytes
|
||||||
|
3072
|
||||||
|
Current command: sqlite3
|
||||||
|
sqltest.sqlite3: SQLite 3.x database
|
||||||
|
n|t
|
||||||
|
1|Line 1
|
||||||
|
2|Line 2
|
||||||
|
1|Line 1
|
||||||
|
2|Line 2
|
||||||
|
n.t
|
||||||
|
1.Line 1
|
||||||
|
2.Line 2
|
||||||
|
1.Line 1
|
||||||
|
2.Line 2
|
||||||
|
nt
|
||||||
|
1Line 1
|
||||||
|
2Line 2
|
||||||
|
n t
|
||||||
|
1 Line 1
|
||||||
|
2 Line 2
|
||||||
|
<TR><TH>n</TH>
|
||||||
|
<TH>t</TH>
|
||||||
|
</TR>
|
||||||
|
<TR><TD>1</TD>
|
||||||
|
<TD>Line 1</TD>
|
||||||
|
</TR>
|
||||||
|
<TR><TD>2</TD>
|
||||||
|
<TD>Line 2</TD>
|
||||||
|
</TR>
|
||||||
|
<TR><TD>1</TD>
|
||||||
|
<TD>Line 1</TD>
|
||||||
|
</TR>
|
||||||
|
<TR><TD>2</TD>
|
||||||
|
<TD>Line 2</TD>
|
||||||
|
</TR>
|
||||||
|
bytes
|
||||||
|
2048
|
||||||
|
bytes
|
||||||
|
2048
|
Loading…
Reference in a new issue