sql: sqlite implemented. sql unittest passes.

This commit is contained in:
Ole Tange 2010-09-09 09:39:57 +02:00
parent 20eab02de2
commit ffd548e168
3 changed files with 55 additions and 47 deletions

View file

@ -6,10 +6,6 @@ dburl = null
sqlite2 sqlite3 support sqlite2 sqlite3 support
parallel: --hashbang alias for --shebang.
sql: .dburl.aliases -> .sql/aliases.
unittest passes.
== FEX == == FEX ==
@ -17,10 +13,6 @@ fex syntax for splitting fields
http://www.semicomplete.com/projects/fex/ http://www.semicomplete.com/projects/fex/
sql :foo 'select * from bar' | parallel --fex '|{1,2}' do_stuff {2} {1} sql :foo 'select * from bar' | parallel --fex '|{1,2}' do_stuff {2} {1}
== Build ==
build.opensuse.org
--autocolsep: Læs alle linjer. --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 Prøv fastlængde: Find tegn, som står i alle linjer på de samme pladser. Risiko for falske pos

View file

@ -116,37 +116,22 @@ cc:Peter Simons <simons@cryp.to>, Sandro Cazzaniga <kharec@mandriva.org>,
Phil Sung <psung@alum.mit.edu>, Michael Shigorin <mike@altlinux.org>, Phil Sung <psung@alum.mit.edu>, Michael Shigorin <mike@altlinux.org>,
Andrew McFague <amcfague@wgen.net>, Steven M. Christensen <sunfreeware@gmail.com> Andrew McFague <amcfague@wgen.net>, Steven M. Christensen <sunfreeware@gmail.com>
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/ download at: http://ftp.gnu.org/gnu/parallel/
New in this release: New in this release:
* Using --shebang GNU Parallel can be used as the parser for a script. * Untested Debian and xUbuntu packages available through OpenSUSE
E.g: #!/usr/bin/parallel --shebang traceroute (followed by lines of build service:
hosts)
* First community generated bugfixes
* Alt Linux package of GNU Parallel. Thanks to Michael Shigorin <mike
at altlinux dot org>
* Sunfreeware package of GNU Parallel. Thanks to Steven M. Christensen
<sunfreeware at gmail.com>
* Untested CentOS, Fedora, Mandriva, RedHat, and SUSE packages
available through OpenSUSE build service:
https://build.opensuse.org/package/show?package=parallel&project=home%3Atange https://build.opensuse.org/package/show?package=parallel&project=home%3Atange
* Review of GNU Parallel. Thanks to Andrew McFague amcfague at wgen dot net * BSD xargs -o (open /dev/tty) is now default for the job running in
http://www.andrew-mcfague.com/linux/utilities-linux/ foreground. Useful for interactive commands like:
commands-every-serious-nix-user-should-know/#parallel ls | parallel -Xuj1 vi
* First 1000 views of the intro video * Renamed .dburl.aliases to .sql/aliases and /etc/sql/aliases.
* sql - a small script to access sql bases from the command line which
is a handy companion to parallel --colsep
= About GNU Parallel = = About GNU Parallel =

59
src/sql
View file

@ -370,6 +370,9 @@ if($database_driver eq "mysql" or
($batch_command,$interactive_command) = postgresql_commands($database_driver,%dburl); ($batch_command,$interactive_command) = postgresql_commands($database_driver,%dburl);
} elsif($database_driver eq "oracle") { } elsif($database_driver eq "oracle") {
($batch_command,$interactive_command) = oracle_commands($database_driver,%dburl); ($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; my $err;
@ -470,7 +473,11 @@ sub database_driver_alias {
"postgresqls" => "postgresqlssl", "postgresqls" => "postgresqlssl",
"pgsqls" => "postgresqlssl", "pgsqls" => "postgresqlssl",
"postgress" => "postgresqlssl", "postgress" => "postgresqlssl",
"pgs" => "postgresqlssl"); "pgs" => "postgresqlssl",
"sqlite" => "sqlite",
"sqlite2" => "sqlite",
"sqlite3" => "sqlite3",
);
return $database_driver_alias{$driver}; return $database_driver_alias{$driver};
} }
@ -562,13 +569,33 @@ sub oracle_commands {
my $ssl = ""; my $ssl = "";
# -L: Do not re-ask for password if it is wrong # -L: Do not re-ask for password if it is wrong
my $common_options = "-L $pass_through_options '$user$password\@$tns' \@$Global::Initfile"; my $common_options = "-L $pass_through_options '$user$password\@$tns' \@$Global::Initfile";
my $batch_command = my $batch_command = "sqlplus -S ".$common_options;
"sqlplus -S ".$common_options; my $interactive_command = "$rlwrap sqlplus ".$common_options;
my $interactive_command =
"$rlwrap sqlplus ".$common_options;
return($batch_command,$interactive_command); 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 # Return the code for 'show processlist' in the chosen database dialect
sub processlist { sub processlist {
my $dbdriver = shift; my $dbdriver = shift;
@ -614,6 +641,10 @@ sub dbsize {
"SELECT ". "SELECT ".
" pg_database_size('".$dburl{'database'}."') AS bytes,". " pg_database_size('".$dburl{'database'}."') AS bytes,".
" pg_size_pretty(pg_database_size('".$dburl{'database'}."')) AS human_readable;"), " 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}) { if($processlist{$dbdriver}) {
return $processlist{$dbdriver}; return $processlist{$dbdriver};
@ -639,11 +670,15 @@ sub tablesize {
if($processlist{$dbdriver}) { if($processlist{$dbdriver}) {
return $processlist{$dbdriver}; return $processlist{$dbdriver};
} else { } else {
print STDERR "dbsize is not implemented for $dbdriver\n"; print STDERR "table size is not implemented for $dbdriver\n";
exit 1; exit 1;
} }
} }
sub undef_as_zero {
my $a = shift;
return $a ? $a : 0;
}
sub is_stdin_terminal { sub is_stdin_terminal {
return (-t STDIN); return (-t STDIN);
@ -732,7 +767,8 @@ sub parse_dburl {
my %options = (); my %options = ();
# mysql://[[user][:password]@][host][:port]/[database[/jobnr]] # 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) ([^:@]*) # Username ($2)
(?: (?:
@ -745,12 +781,8 @@ sub parse_dburl {
([^/]*)? # Port ($5) ([^/]*)? # Port ($5)
)? )?
(?: (?:
/+ /
([^/]*)? # Database ($6) (.*)? # Database ($6)
(?:
/+
([^/]*)? # Job ($7)
)?
)? )?
!x) { !x) {
$options{databasedriver} = undef_if_empty($1); $options{databasedriver} = undef_if_empty($1);
@ -759,7 +791,6 @@ 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{job} = undef_if_empty($7);
} else { } else {
Usage("$url is not a valid DBURL"); Usage("$url is not a valid DBURL");
exit -1; exit -1;