From ffd548e168e50767ebc46acf7ffe8fd350146664 Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Thu, 9 Sep 2010 09:39:57 +0200 Subject: [PATCH] sql: sqlite implemented. sql unittest passes. --- doc/FUTURE_IDEAS | 8 ------ doc/release_new_version | 31 ++++++-------------- src/sql | 63 ++++++++++++++++++++++++++++++----------- 3 files changed, 55 insertions(+), 47 deletions(-) diff --git a/doc/FUTURE_IDEAS b/doc/FUTURE_IDEAS index 4a36a374..e7e7de4d 100644 --- a/doc/FUTURE_IDEAS +++ b/doc/FUTURE_IDEAS @@ -6,10 +6,6 @@ dburl = null sqlite2 sqlite3 support -parallel: --hashbang alias for --shebang. -sql: .dburl.aliases -> .sql/aliases. -unittest passes. - == FEX == @@ -17,10 +13,6 @@ fex syntax for splitting fields http://www.semicomplete.com/projects/fex/ sql :foo 'select * from bar' | parallel --fex '|{1,2}' do_stuff {2} {1} -== Build == - -build.opensuse.org - --autocolsep: Læs alle linjer. Prøv fastlængde: Find tegn, som står i alle linjer på de samme pladser. Risiko for falske pos diff --git a/doc/release_new_version b/doc/release_new_version index 25ab0689..0014653b 100644 --- a/doc/release_new_version +++ b/doc/release_new_version @@ -116,37 +116,22 @@ cc:Peter Simons , Sandro Cazzaniga , Phil Sung , Michael Shigorin , Andrew McFague , Steven M. Christensen -Subject: GNU Parallel 20100906 released +Subject: GNU Parallel 2010XXXX released -GNU Parallel 20100906 has been released. It is available for +GNU Parallel 2010XXXX has been released. It is available for download at: http://ftp.gnu.org/gnu/parallel/ New in this release: -* Using --shebang GNU Parallel can be used as the parser for a script. - E.g: #!/usr/bin/parallel --shebang traceroute (followed by lines of - hosts) - -* First community generated bugfixes - -* Alt Linux package of GNU Parallel. Thanks to Michael Shigorin - -* Sunfreeware package of GNU Parallel. Thanks to Steven M. Christensen - - -* Untested CentOS, Fedora, Mandriva, RedHat, and SUSE packages - available through OpenSUSE build service: +* Untested Debian and xUbuntu packages available through OpenSUSE + build service: https://build.opensuse.org/package/show?package=parallel&project=home%3Atange -* Review of GNU Parallel. Thanks to Andrew McFague amcfague at wgen dot net - http://www.andrew-mcfague.com/linux/utilities-linux/ - commands-every-serious-nix-user-should-know/#parallel +* BSD xargs -o (open /dev/tty) is now default for the job running in + foreground. Useful for interactive commands like: + ls | parallel -Xuj1 vi -* First 1000 views of the intro video - -* sql - a small script to access sql bases from the command line which - is a handy companion to parallel --colsep +* Renamed .dburl.aliases to .sql/aliases and /etc/sql/aliases. = About GNU Parallel = diff --git a/src/sql b/src/sql index 2c87551c..8a9961ac 100755 --- a/src/sql +++ b/src/sql @@ -370,6 +370,9 @@ if($database_driver eq "mysql" or ($batch_command,$interactive_command) = postgresql_commands($database_driver,%dburl); } elsif($database_driver eq "oracle") { ($batch_command,$interactive_command) = oracle_commands($database_driver,%dburl); +} elsif($database_driver eq "sqlite" or + $database_driver eq "sqlite3") { + ($batch_command,$interactive_command) = sqlite_commands($database_driver,%dburl); } my $err; @@ -470,7 +473,11 @@ sub database_driver_alias { "postgresqls" => "postgresqlssl", "pgsqls" => "postgresqlssl", "postgress" => "postgresqlssl", - "pgs" => "postgresqlssl"); + "pgs" => "postgresqlssl", + "sqlite" => "sqlite", + "sqlite2" => "sqlite", + "sqlite3" => "sqlite3", + ); return $database_driver_alias{$driver}; } @@ -490,7 +497,7 @@ sub mysql_commands { $ssl="--ssl"; } # -C: Compression if both ends support it - $batch_command = + $batch_command = "mysql -C $pass_through_options $no_headers $html $ssl $host $user $port $password $database"; $interactive_command = $batch_command; return($batch_command,$interactive_command); @@ -511,7 +518,7 @@ sub postgresql_commands { if ($database_driver eq "postgresqlssl") { $ssl="PGSSLMODE=require"; } - $batch_command = + $batch_command = "$ssl $password psql $pass_through_options $sep $no_headers $html $host $user $port $database"; $interactive_command = $batch_command; @@ -562,13 +569,33 @@ sub oracle_commands { my $ssl = ""; # -L: Do not re-ask for password if it is wrong my $common_options = "-L $pass_through_options '$user$password\@$tns' \@$Global::Initfile"; - my $batch_command = - "sqlplus -S ".$common_options; - my $interactive_command = - "$rlwrap sqlplus ".$common_options; + my $batch_command = "sqlplus -S ".$common_options; + my $interactive_command = "$rlwrap sqlplus ".$common_options; return($batch_command,$interactive_command); } +sub sqlite_commands { + my ($database_driver,%opt) = (@_); + if(not find_command_in_path($database_driver)) { + print STDERR "Database driver '$database_driver' not supported\n"; + exit -1; + } + my $sep = defined($::opt_s) ? "-separator '$::opt_s'" : ""; + my $password = defined($opt{'password'}) ? "--password=".$opt{'password'} : ""; + my $host = defined($opt{'host'}) ? "--host=".$opt{'host'} : ""; + my $port = defined($opt{'port'}) ? "--port=".$opt{'port'} : ""; + my $user = defined($opt{'user'}) ? "--user=".$opt{'user'} : ""; + my $database = defined($opt{'database'}) ? $opt{'database'} : ""; + my $html = defined($::opt_html) ? "-html" : ""; + my $no_headers = defined($::opt_n) ? "-noheader" : "-header"; + my $ssl = ""; + $batch_command = + "$database_driver $pass_through_options $sep $no_headers $html $database"; + $interactive_command = $batch_command; + return($batch_command,$interactive_command); +} + + # Return the code for 'show processlist' in the chosen database dialect sub processlist { my $dbdriver = shift; @@ -614,6 +641,10 @@ sub dbsize { "SELECT ". " pg_database_size('".$dburl{'database'}."') AS bytes,". " pg_size_pretty(pg_database_size('".$dburl{'database'}."')) AS human_readable;"), + "sqlite" => ( + "SELECT ".(undef_as_zero(-s $dburl{'database'}))." AS bytes;"), + "sqlite3" => ( + "SELECT ".(undef_as_zero(-s $dburl{'database'}))." AS bytes;"), ); if($processlist{$dbdriver}) { return $processlist{$dbdriver}; @@ -639,11 +670,15 @@ sub tablesize { if($processlist{$dbdriver}) { return $processlist{$dbdriver}; } else { - print STDERR "dbsize is not implemented for $dbdriver\n"; + print STDERR "table size is not implemented for $dbdriver\n"; exit 1; } } +sub undef_as_zero { + my $a = shift; + return $a ? $a : 0; +} sub is_stdin_terminal { return (-t STDIN); @@ -732,7 +767,8 @@ sub parse_dburl { my %options = (); # mysql://[[user][:password]@][host][:port]/[database[/jobnr]] - if($url=~m!((?:oracle|ora|mysql|pg|postgres|postgresql)(?:s|ssl|)):// # Databasedriver ($1) + if($url=~m!((?:oracle|ora|mysql|pg|postgres|postgresql)(?:s|ssl|)| + (?:sqlite|sqlite2|sqlite3)):// # Databasedriver ($1) (?: ([^:@]*) # Username ($2) (?: @@ -745,12 +781,8 @@ sub parse_dburl { ([^/]*)? # Port ($5) )? (?: - /+ - ([^/]*)? # Database ($6) - (?: - /+ - ([^/]*)? # Job ($7) - )? + / + (.*)? # Database ($6) )? !x) { $options{databasedriver} = undef_if_empty($1); @@ -759,7 +791,6 @@ sub parse_dburl { $options{host} = undef_if_empty($4); $options{port} = undef_if_empty($5); $options{database} = undef_if_empty($6); - $options{job} = undef_if_empty($7); } else { Usage("$url is not a valid DBURL"); exit -1;