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

include_sql_query requests unuseful parameters for CSV database driver (#1437) #1505

Merged
merged 2 commits into from
Nov 16, 2022
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
26 changes: 15 additions & 11 deletions src/lib/Sympa/Config/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ our %pinfo = (
},
db_host => {
context => [qw(site)],
order => 2.11,
order => 2.12,
group => 'database',
importance => 100,
#default => 'localhost',
Expand All @@ -333,22 +333,23 @@ our %pinfo = (
},
db_port => {
context => [qw(site)],
order => 2.12,
order => 2.13,
group => 'database',
importance => 100,
gettext_id => 'Port of the database server',
format => '[-/\w]+',
},
db_name => {
context => [qw(site)],
order => 2.13,
order => 2.11,
group => 'database',
importance => 100,
default => 'sympa',
gettext_id => 'Name of the database',
gettext_comment =>
"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).",
format => '.+',
occurrence => '1',
},
db_user => {
context => [qw(site)],
Expand Down Expand Up @@ -3709,7 +3710,8 @@ our %pinfo = (
order => 2,
gettext_id => "remote host",
format_s => '$host',
# occurrence => '1', # Not required for ODBC
# Not required for ODBC and SQLite. Optional for Oracle.
# occurrence => '1',
not_before => '6.2.57b.1',
},
host => {
Expand All @@ -3725,7 +3727,7 @@ our %pinfo = (
},
db_name => {
context => [qw(list)],
order => 4,
order => 1.7,
gettext_id => "database name",
format => '\S+',
occurrence => '1'
Expand Down Expand Up @@ -3753,7 +3755,6 @@ our %pinfo = (
order => 6,
gettext_id => "remote user",
format => '\S+',
occurrence => '1',
not_before => '6.2.57b.1',
},
user => {
Expand Down Expand Up @@ -3787,7 +3788,9 @@ our %pinfo = (
order => 9,
gettext_id =>
"Directory where the database is stored (used for DBD::CSV only)",
format => '.+'
format => '.+',
obsolete => 'db_name',
not_after => '6.2.70',
},
nosync_time_ranges => {
context => [qw(list)],
Expand Down Expand Up @@ -4293,14 +4296,14 @@ our %pinfo = (
},
db_name => {
context => [qw(list)],
order => 4,
order => 1.7,
gettext_id => "database name",
format => '\S+',
occurrence => '1'
},
db_options => {
context => [qw(list)],
order => 4.5,
order => 4,
gettext_id => "connection options",
format => '.+',
not_before => '6.2.57b.1',
Expand All @@ -4321,7 +4324,6 @@ our %pinfo = (
order => 6,
gettext_id => "remote user",
format => '\S+',
occurrence => '1',
not_before => '6.2.57b.1',
},
user => {
Expand Down Expand Up @@ -4355,7 +4357,9 @@ our %pinfo = (
order => 9,
gettext_id =>
"Directory where the database is stored (used for DBD::CSV only)",
format => '.+'
format => '.+',
obsolete => 'db_name',
not_after => '6.2.70',
},
email_entry => {
context => [qw(list)],
Expand Down
8 changes: 5 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_name db_user)];
use constant required_parameters => [qw(db_name)];
use constant optional_modules => [];
use constant optional_parameters =>
[qw(db_host db_port db_passwd db_options db_env)];
[qw(db_host db_port db_user db_passwd db_options db_env)];

sub translate_type {
return $_[1];
Expand Down Expand Up @@ -87,9 +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_name', 'db_user']>.
By default, returns C<['db_name']>.

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

Expand Down
10 changes: 6 additions & 4 deletions src/lib/Sympa/DatabaseDriver/CSV.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ use warnings;
use base qw(Sympa::DatabaseDriver);

use constant required_modules => [qw(DBD::CSV)];
use constant required_parameters => [qw(f_dir)];
use constant required_parameters => [qw(db_name)];
use constant optional_parameters => [qw(db_options)];

sub build_connect_string {
my $self = shift;

my $connect_string = 'DBI:CSV:f_dir=' . $self->{'f_dir'};
$connect_string .= ';' . $self->{'db_options'}
if defined $self->{'db_options'};
return undef unless 0 == index $self->{db_name}, '/';

my $connect_string = sprintf 'DBI:CSV:f_dir=%s', $self->{db_name};
$connect_string .= sprintf ';%s', $self->{db_options}
if defined $self->{db_options};
return $connect_string;
}

Expand Down