sql: basic dburl?sqlstatement works. No unittest

This commit is contained in:
Ole Tange 2010-09-09 23:21:11 +02:00
parent 654eb4bfa0
commit 0db41520c3
2 changed files with 21 additions and 10 deletions

View file

@ -4,7 +4,11 @@ Unittest:
dburl = : dburl = :
dburl = null dburl = null
sqlite2 sqlite3 support Denne med '?' skal vel også virke:
sql mysql:///mydb?'SELECT * FROM foo'
el.
sql 'mysql:///mydb?SELECT * FROM foo'
== FEX == == FEX ==

25
src/sql
View file

@ -393,6 +393,10 @@ if(defined $::opt_tablesize) {
unshift @ARGV, tablesize($database_driver,%dburl); unshift @ARGV, tablesize($database_driver,%dburl);
} }
if($dburl{'statement'}) {
unshift @ARGV,$dburl{'statement'};
}
do { do {
if(@ARGV) { if(@ARGV) {
$::opt_debug and print "$batch_command\n"; $::opt_debug and print "$batch_command\n";
@ -449,8 +453,6 @@ sub parse_options {
if(defined $::opt_version) { version(); exit(0); } if(defined $::opt_version) { version(); exit(0); }
} }
sub database_driver_alias { sub database_driver_alias {
my $driver = shift; my $driver = shift;
my %database_driver_alias = ("mysql" => "mysql", my %database_driver_alias = ("mysql" => "mysql",
@ -675,11 +677,6 @@ sub tablesize {
} }
} }
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);
} }
@ -765,7 +762,7 @@ sub check_permissions {
sub parse_dburl { sub parse_dburl {
my $url = shift; my $url = shift;
my %options = (); my %options = ();
# mysql://[[user][:password]@][host][:port]/[database[/jobnr]] # mysql://[[user][:password]@][host][:port]/[database[?sql statement]]
if($url=~m!((?:oracle|ora|mysql|pg|postgres|postgresql)(?:s|ssl|)| if($url=~m!((?:oracle|ora|mysql|pg|postgres|postgresql)(?:s|ssl|)|
(?:sqlite|sqlite2|sqlite3)):// # Databasedriver ($1) (?:sqlite|sqlite2|sqlite3)):// # Databasedriver ($1)
@ -782,7 +779,11 @@ sub parse_dburl {
)? )?
(?: (?:
/ /
(.*)? # Database ($6) ([^?]*)? # Database ($6)
)?
(?:
\?
(.*)? # Statement ($7)
)? )?
!x) { !x) {
$options{databasedriver} = undef_if_empty($1); $options{databasedriver} = undef_if_empty($1);
@ -791,6 +792,7 @@ 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{statement} = undef_if_empty($7);
} else { } else {
Usage("$url is not a valid DBURL"); Usage("$url is not a valid DBURL");
exit -1; exit -1;
@ -805,6 +807,11 @@ sub undef_if_empty {
return $_[0]; return $_[0];
} }
sub undef_as_zero {
my $a = shift;
return $a ? $a : 0;
}
sub version { sub version {
# Returns: N/A # Returns: N/A
print join("\n", print join("\n",