From e63e97916cf08ef933b007ff06f9c207d195191b Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Fri, 10 Sep 2010 00:58:34 +0200 Subject: [PATCH] sql: RFC3986 calls the statement part a query. Let's do that, too. sql: test sql02 and results. --- src/sql | 34 ++++++++-------- unittest/tests-to-run/sql02.sh | 26 ++++++++++++ unittest/wanted-results/sql02 | 73 ++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 16 deletions(-) create mode 100644 unittest/tests-to-run/sql02.sh create mode 100644 unittest/wanted-results/sql02 diff --git a/src/sql b/src/sql index b386150a..057d54fa 100755 --- a/src/sql +++ b/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 @@ -333,9 +333,11 @@ A copy of the full license is included in the file as cc-by-sa.txt. =head1 DEPENDENCIES GNU B uses Perl. If B is installed, MySQL dburls will -work. If B is installed, PostgreSQL dburls will work. If -B is installed, Oracle dburls will work. If B is -installed, GNU B will have a command history for Oracle. +work. If B is installed, PostgreSQL dburls will work. If +B is installed, SQLite2 dburls will work. If B is +installed, SQLite3 dburls will work. If B is installed, +Oracle dburls will work. If B is installed, GNU B will +have a command history for Oracle. =head1 FILES @@ -347,7 +349,7 @@ installed, GNU B will have a command history for Oracle. =head1 SEE ALSO -B(1), B(1), B(1), B(1) +B(1), B(1), B(1), B(1), B(1), B(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; diff --git a/unittest/tests-to-run/sql02.sh b/unittest/tests-to-run/sql02.sh new file mode 100644 index 00000000..1e99fb4e --- /dev/null +++ b/unittest/tests-to-run/sql02.sh @@ -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 + diff --git a/unittest/wanted-results/sql02 b/unittest/wanted-results/sql02 new file mode 100644 index 00000000..0242351d --- /dev/null +++ b/unittest/wanted-results/sql02 @@ -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 +nt +1 +Line 1 + +2 +Line 2 + +1 +Line 1 + +2 +Line 2 + +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 +n +t + +1 +Line 1 + +2 +Line 2 + +1 +Line 1 + +2 +Line 2 + +bytes +2048 +bytes +2048