mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-11-25 23:47:53 +00:00
sql: alias can now contain statement
This commit is contained in:
parent
c9b2a3f727
commit
944a4fdd4f
18
src/sql
18
src/sql
|
@ -149,18 +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:
|
||||||
vendor://[user[:password]@][host][:port]/[database]
|
[sql:]vendor://[user[:password]@][host][:port]/[database][?sqlstatement]
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
mysql://user:pa55w0rd@mysqlserver/database
|
mysql://user:pa55w0rd@mysqlserver/database
|
||||||
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;
|
||||||
|
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)
|
postgresssl, pgssl, postgresqls, pgsqls, postgress), SQLite (sqlite2,
|
||||||
|
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
|
||||||
|
@ -175,9 +178,11 @@ Example of aliases:
|
||||||
# Short form of mysql://`whoami`:nopassword@localhost:33333/mydb
|
# Short form of mysql://`whoami`:nopassword@localhost:33333/mydb
|
||||||
:myalias4 mysql://:33333/mydb
|
:myalias4 mysql://:33333/mydb
|
||||||
# Alias for an alias
|
# Alias for an alias
|
||||||
:m :myalias4
|
:m :myalias4
|
||||||
# the sortest alias possible
|
# the sortest alias possible
|
||||||
: sqlite:////tmp/mydefault.sqlite
|
: sqlite2:////tmp/mydefault.sqlite
|
||||||
|
# Including an SQL statement
|
||||||
|
:stm sqlite:////tmp/file.sqlite?select * from foo;
|
||||||
|
|
||||||
=head1 EXAMPLES
|
=head1 EXAMPLES
|
||||||
|
|
||||||
|
@ -743,7 +748,7 @@ sub get_alias {
|
||||||
|
|
||||||
my $dburl;
|
my $dburl;
|
||||||
for (@urlalias) {
|
for (@urlalias) {
|
||||||
/^$alias_part\s+(\S+)/ and do { $dburl = $1; last; }
|
/^$alias_part\s+(\S+.*)/ and do { $dburl = $1; last; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if($dburl) {
|
if($dburl) {
|
||||||
|
@ -806,6 +811,7 @@ sub parse_dburl {
|
||||||
$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{statement} = undef_if_empty(uri_unescape($7));
|
||||||
|
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},
|
||||||
|
|
|
@ -25,6 +25,11 @@ echo :cyclic3 :cyclic >> ~/.sql/aliases
|
||||||
perl -i -ne '$seen{$_}++ || print' ~/.sql/aliases
|
perl -i -ne '$seen{$_}++ || print' ~/.sql/aliases
|
||||||
stdout sql ":cyclic3?SELECT 'NO IT DID NOT' as 'Test if :cyclic is found works';"
|
stdout sql ":cyclic3?SELECT 'NO IT DID NOT' as 'Test if :cyclic is found works';"
|
||||||
|
|
||||||
|
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
|
||||||
|
stdout sql :testselect
|
||||||
|
|
||||||
echo "### Test empty dburl"
|
echo "### Test empty dburl"
|
||||||
stdout sql ''
|
stdout sql ''
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue