+ Add a system to add connect options for dbi
This commit is contained in:
parent
0f43e9d2d4
commit
61968aacfb
|
@ -63,6 +63,7 @@ sub new {
|
||||||
{ "datasource:s@" => { name => 'data_source' },
|
{ "datasource:s@" => { name => 'data_source' },
|
||||||
"username:s@" => { name => 'username' },
|
"username:s@" => { name => 'username' },
|
||||||
"password:s@" => { name => 'password' },
|
"password:s@" => { name => 'password' },
|
||||||
|
"connect-options:s@" => { name => 'connect_options' },
|
||||||
"sql-errors-exit:s" => { name => 'sql_errors_exit', default => 'unknown' },
|
"sql-errors-exit:s" => { name => 'sql_errors_exit', default => 'unknown' },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -77,6 +78,8 @@ sub new {
|
||||||
$self->{data_source} = undef;
|
$self->{data_source} = undef;
|
||||||
$self->{username} = undef;
|
$self->{username} = undef;
|
||||||
$self->{password} = undef;
|
$self->{password} = undef;
|
||||||
|
$self->{connect_options} = undef;
|
||||||
|
$self->{connect_options_hash} = {};
|
||||||
|
|
||||||
# Sometimes, we need to set ENV
|
# Sometimes, we need to set ENV
|
||||||
$self->{env} = undef;
|
$self->{env} = undef;
|
||||||
|
@ -119,6 +122,7 @@ sub check_options {
|
||||||
$self->{data_source} = (defined($self->{option_results}->{data_source})) ? shift(@{$self->{option_results}->{data_source}}) : undef;
|
$self->{data_source} = (defined($self->{option_results}->{data_source})) ? shift(@{$self->{option_results}->{data_source}}) : undef;
|
||||||
$self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : undef;
|
$self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : undef;
|
||||||
$self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : undef;
|
$self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : undef;
|
||||||
|
$self->{connect_options} = (defined($self->{option_results}->{connect_options})) ? shift(@{$self->{option_results}->{connect_options}}) : undef;
|
||||||
$self->{env} = (defined($self->{option_results}->{env})) ? shift(@{$self->{option_results}->{env}}) : undef;
|
$self->{env} = (defined($self->{option_results}->{env})) ? shift(@{$self->{option_results}->{env}}) : undef;
|
||||||
$self->{sql_errors_exit} = $self->{option_results}->{sql_errors_exit};
|
$self->{sql_errors_exit} = $self->{option_results}->{sql_errors_exit};
|
||||||
|
|
||||||
|
@ -126,6 +130,15 @@ sub check_options {
|
||||||
$self->{output}->add_option_msg(short_msg => "Need to specify data_source arguments.");
|
$self->{output}->add_option_msg(short_msg => "Need to specify data_source arguments.");
|
||||||
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
|
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
|
||||||
}
|
}
|
||||||
|
if (defined($self->{connect_options}) && $self->{connect_options} ne '') {
|
||||||
|
foreach my $entry (split /,/, $self->{connect_options}) {
|
||||||
|
if ($entry !~ /^\s*([^=]+)=([^=]+)\s*$/) {
|
||||||
|
$self->{output}->add_option_msg(short_msg => "Wrong format for --connect-options '" . $entry . "'.");
|
||||||
|
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
|
||||||
|
}
|
||||||
|
$self->{connect_options_hash}->{$1} = $2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (scalar(@{$self->{option_results}->{data_source}}) == 0) {
|
if (scalar(@{$self->{option_results}->{data_source}}) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -175,7 +188,7 @@ sub connect {
|
||||||
"DBI:". $self->{data_source},
|
"DBI:". $self->{data_source},
|
||||||
$self->{username},
|
$self->{username},
|
||||||
$self->{password},
|
$self->{password},
|
||||||
{ "RaiseError" => 0, "PrintError" => 0, "AutoCommit" => 1 }
|
{ "RaiseError" => 0, "PrintError" => 0, "AutoCommit" => 1, %{$self->{connect_options_hash}} }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!defined($self->{instance})) {
|
if (!defined($self->{instance})) {
|
||||||
|
@ -264,6 +277,11 @@ Database username.
|
||||||
|
|
||||||
Database password.
|
Database password.
|
||||||
|
|
||||||
|
=item B<--connect-options>
|
||||||
|
|
||||||
|
Add options in database connect.
|
||||||
|
Format: name=value,name2=value2,...
|
||||||
|
|
||||||
=item B<--sql-errors-exit>
|
=item B<--sql-errors-exit>
|
||||||
|
|
||||||
Exit code for DB Errors (default: unknown)
|
Exit code for DB Errors (default: unknown)
|
||||||
|
|
Loading…
Reference in New Issue