mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-11-25 23:47:53 +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
32
src/sql
32
src/sql
|
@ -149,21 +149,21 @@ For this to work B<--shebang> or B<-Y> must be set as the first option.
|
|||
=head1 DBURL
|
||||
|
||||
A DBURL has the following syntax:
|
||||
[sql:]vendor://[user[:password]@][host][:port]/[database][?sqlstatement]
|
||||
[sql:]vendor://[user[:password]@][host][:port]/[database][?sqlquery]
|
||||
|
||||
Examples:
|
||||
mysql://user:pa55w0rd@mysqlserver/database
|
||||
sql:oracle://scott:tiger@oracleserver/xe
|
||||
postgresql://user:pa55w0rd@pg.example.com/db
|
||||
pg:///
|
||||
sqlite2:////tmp/db.sqlite?select * from foo;
|
||||
sql:sqlite2:////tmp/db.sqlite?select * from foo;
|
||||
sqlite3:///../db.sqlite3?select%20*%20from%20foo;
|
||||
|
||||
Currently supported vendors: MySQL (mysql), MySQL with SSL (mysqls,
|
||||
mysqlssl), Oracle (oracle, ora), PostgreSQL (postgresql, pg, pgsql,
|
||||
postgres), PostgreSQL with SSL (postgresqlssl, pgs, pgsqlssl,
|
||||
postgresssl, pgssl, postgresqls, pgsqls, postgress), SQLite (sqlite2,
|
||||
sqlite3).
|
||||
postgresssl, pgssl, postgresqls, pgsqls, postgress), SQLite2 (sqlite,
|
||||
sqlite2), SQLite3 (sqlite3).
|
||||
|
||||
Aliases must start with ':' and are read from
|
||||
/etc/sql/aliases and ~/.sql/aliases. The user's own
|
||||
|
@ -181,8 +181,8 @@ Example of aliases:
|
|||
:m :myalias4
|
||||
# the sortest alias possible
|
||||
: sqlite2:////tmp/mydefault.sqlite
|
||||
# Including an SQL statement
|
||||
:stm sqlite:////tmp/file.sqlite?select * from foo;
|
||||
# Including an SQL query
|
||||
:query sqlite:////tmp/file.sqlite?select * from foo;
|
||||
|
||||
=head1 EXAMPLES
|
||||
|
||||
|
@ -334,8 +334,10 @@ A copy of the full license is included in the file as cc-by-sa.txt.
|
|||
|
||||
GNU B<sql> uses Perl. If B<mysql> is installed, MySQL dburls will
|
||||
work. If B<psql> is installed, PostgreSQL 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.
|
||||
B<sqlite> is installed, SQLite2 dburls will work. If B<sqlite3> is
|
||||
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
|
||||
|
@ -347,7 +349,7 @@ installed, GNU B<sql> will have a command history for Oracle.
|
|||
|
||||
=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
|
||||
|
||||
|
@ -399,8 +401,8 @@ if(defined $::opt_tablesize) {
|
|||
unshift @ARGV, tablesize($database_driver,%dburl);
|
||||
}
|
||||
|
||||
if($dburl{'statement'}) {
|
||||
unshift @ARGV,$dburl{'statement'};
|
||||
if($dburl{'query'}) {
|
||||
unshift @ARGV,$dburl{'query'};
|
||||
}
|
||||
|
||||
do {
|
||||
|
@ -779,7 +781,7 @@ sub check_permissions {
|
|||
sub parse_dburl {
|
||||
my $url = shift;
|
||||
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:'
|
||||
((?:oracle|ora|mysql|pg|postgres|postgresql)(?:s|ssl|)|
|
||||
|
@ -801,7 +803,7 @@ sub parse_dburl {
|
|||
)?
|
||||
(?:
|
||||
\?
|
||||
(.*)? # Statement ($7)
|
||||
(.*)? # Query ($7)
|
||||
)?
|
||||
!x) {
|
||||
$options{databasedriver} = undef_if_empty($1);
|
||||
|
@ -810,12 +812,12 @@ sub parse_dburl {
|
|||
$options{host} = undef_if_empty($4);
|
||||
$options{port} = undef_if_empty($5);
|
||||
$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("databasedriver ",$options{databasedriver}, " user ", $options{user},
|
||||
" password ", $options{password}, " host ", $options{host},
|
||||
" port ", $options{port}, " database ", $options{database},
|
||||
" statement ",$options{statement}, "\n");
|
||||
" query ",$options{query}, "\n");
|
||||
} else {
|
||||
Usage("$url is not a valid DBURL");
|
||||
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