Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oracle: Make db_name parameter allow net service name or connection identifier along with SID #431

Merged
merged 5 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/Conf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ sub load_sql_filter {
'db_type' =>
{'format' => 'mysql|MySQL|Oracle|Pg|PostgreSQL|SQLite',},
'db_name' => {'format' => '.*', 'occurrence' => '1',},
'db_host' => {'format' => '.*', 'occurrence' => '1',},
'db_host' => {'format' => '.*', 'occurrence' => '0-1',},
'statement' => {'format' => '.*', 'occurrence' => '1',},
'db_user' => {'format' => '.*', 'occurrence' => '0-1',},
'db_passwd' => {'format' => '.*', 'occurrence' => '0-1',},
Expand Down
5 changes: 3 additions & 2 deletions src/lib/Sympa/ConfDef.pm
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,14 @@ our @params = (
'edit' => '1',
},
{ 'name' => 'db_host',
'default' => 'localhost',
#'default' => 'localhost',
'sample' => 'localhost',
'gettext_id' => 'Hostname of the database server',
'gettext_comment' =>
'With PostgreSQL, you can also use the path to Unix Socket Directory, e.g. "/var/run/postgresql" for connection with Unix domain socket.',
'file' => 'sympa.conf',
'edit' => '1',
'optional' => 1,
},
{ 'name' => 'db_port',
'default' => undef,
Expand All @@ -138,7 +139,7 @@ our @params = (
'file' => 'sympa.conf',
'edit' => '1',
'gettext_comment' =>
'With SQLite, this must be the full path to database file. With Oracle Database, this must be Oracle SID.',
"With SQLite, this must be the full path to database file.\nWith Oracle Database, this must be SID, net service name or easy connection identifier (to use net service name, db_host should be set to \"none\" and HOST, PORT and SERVICE_NAME should be defined in tnsnames.ora file).",
},
{ 'name' => 'db_user',
'default' => 'user_name',
Expand Down
10 changes: 7 additions & 3 deletions src/lib/Sympa/DatabaseDriver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ use warnings;
use base qw(Sympa::Database);

use constant required_modules => [];
use constant required_parameters => [qw(db_host db_name db_user)];
use constant required_parameters => [qw(db_name db_user)];
use constant optional_modules => [];
use constant optional_parameters =>
[qw(db_port db_passwd db_timeout db_options db_env)];
[qw(db_host db_port db_passwd db_options db_env)];

sub translate_type {
return $_[1];
Expand Down Expand Up @@ -87,7 +87,11 @@ By default, no packages are required.

I<Overridable>.
Returns an arrayref including names of required (not optional) parameters.
By default, returns C<['db_host', 'db_name', 'db_user']>.
By default, returns C<['db_name', 'db_user']>.

I<Note>:
On Sympa prior to 6.2.37b.2, it by default returned
C<['db_host', 'db_name', 'db_user']>.

=item optional_modules ( )

Expand Down
4 changes: 3 additions & 1 deletion src/lib/Sympa/DatabaseDriver/MySQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ sub build_connect_string {
my $self = shift;

my $connect_string =
'DBI:mysql:' . $self->{'db_name'} . ':' . $self->{'db_host'};
'DBI:mysql:'
. $self->{'db_name'} . ':'
. ($self->{'db_host'} || 'localhost');
$connect_string .= ';port=' . $self->{'db_port'}
if defined $self->{'db_port'};
$connect_string .= ';' . $self->{'db_options'}
Expand Down
10 changes: 7 additions & 3 deletions src/lib/Sympa/DatabaseDriver/Oracle.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ sub build_connect_string {
my $self = shift;

my $connect_string = "DBI:Oracle:";
if ($self->{'db_host'} and $self->{'db_name'}) {
if ( $self->{'db_host'}
and $self->{'db_host'} ne 'none'
and $self->{'db_name'}) {
$connect_string .= "host=$self->{'db_host'};sid=$self->{'db_name'}";
$connect_string .= ';port=' . $self->{'db_port'}
if defined $self->{'db_port'};
} elsif ($self->{'db_name'}) {
$connect_string .= $self->{'db_name'};
}
$connect_string .= ';port=' . $self->{'db_port'}
if defined $self->{'db_port'};
$connect_string .= ';' . $self->{'db_options'}
if defined $self->{'db_options'};
return $connect_string;
Expand Down
5 changes: 4 additions & 1 deletion src/lib/Sympa/DatabaseDriver/PostgreSQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ sub build_connect_string {
my $self = shift;

my $connect_string =
"DBI:Pg:dbname=$self->{'db_name'};host=$self->{'db_host'}";
'DBI:Pg:dbname='
. $self->{'db_name'}
. ';host='
. ($self->{'db_host'} || 'localhost');
$connect_string .= ';port=' . $self->{'db_port'}
if defined $self->{'db_port'};
$connect_string .= ';' . $self->{'db_options'}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Sympa/ListDef.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,8 @@ our %pinfo = (
'order' => 2,
'gettext_id' => "remote host",
format_s => '$host',
'occurrence' => '1'
# Not required for ODBC and SQLite. Optional for Oracle.
#'occurrence' => '1'
},
'db_port' => {
'order' => 3,
Expand Down
8 changes: 2 additions & 6 deletions src/lib/Sympa/Scenario.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1545,12 +1545,8 @@ sub search {
%{$sql_conf->{'sql_named_filter_query'}}
);
unless ($db and $db->connect()) {
$log->syslog(
'notice',
'Unable to connect to the SQL server %s:%d',
$sql_conf->{'db_host'},
$sql_conf->{'db_port'}
);
$log->syslog('notice',
'Unable to connect to the SQL server %s', $db);
return undef;
}

Expand Down