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

Deprecate datetime field type in database #223

Merged
merged 3 commits into from
Mar 12, 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
14 changes: 4 additions & 10 deletions src/lib/Sympa/Database.pm
Original file line number Diff line number Diff line change
Expand Up @@ -473,22 +473,16 @@ sub quote {
## This sub takes a single argument: the name of the field to be used in
## the query.
##
sub get_canonical_write_date {
my $self = shift;
my $field = shift;
return $self->get_formatted_date({'mode' => 'write', 'target' => $field});
}
# Moved to Sympa::Upgrade::_get_canonical_write_date().
#sub get_canonical_write_date;

## Returns a character string corresponding to the expression to use in
## a write query (e.g. UPDATE or INSERT) for the value given as argument.
## This sub takes a single argument: the value of the date to be used in
## the query.
##
sub get_canonical_read_date {
my $self = shift;
my $value = shift;
return $self->get_formatted_date({'mode' => 'read', 'target' => $value});
}
# Moved to Sympa::Upgrade::_get_canonical_read_date().
#sub get_canonical_read_date;

# We require that user also matches (except SQLite).
sub get_id {
Expand Down
57 changes: 42 additions & 15 deletions src/lib/Sympa/DatabaseDescription.pm
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,30 @@ my %full_db_struct = (
'doc' => 'FIXME',
'order' => 10,
},
'date_subscriber' => {
'struct' => 'datetime',
#'date_subscriber' => {
# 'struct' => 'datetime',
# 'doc' => 'date of subscription',
# 'not_null' => 1,
# 'order' => 11,
#},
'date_epoch_subscriber' => {
'struct' => 'int(11)',
'doc' => 'date of subscription',
'not_null' => 1,
'order' => 11,
},
'update_subscriber' => {
'struct' => 'datetime',
'order' => 11.5,
},
# Obsoleted as of 6.2.25b.2. Use update_epoch_subscriber.
#'update_subscriber' => {
# 'struct' => 'datetime',
# 'doc' =>
# 'the latest date where subscription is confirmed by subscriber',
# 'order' => 12,
#},
'update_epoch_subscriber' => {
'struct' => 'int(11)',
'doc' =>
'the latest date where subscription is confirmed by subscriber',
'order' => 12,
'the last time when subscription is confirmed by subscriber',
'order' => 12.5,
},
'comment_subscriber' => {
'struct' => 'varchar(150)',
Expand Down Expand Up @@ -883,16 +896,28 @@ my %full_db_struct = (
'privilege level for this owner, value //normal// or //privileged//. The related privilege are listed in edit_list.conf. ',
'order' => 5,
},
'date_admin' => {
'struct' => 'datetime',
#'date_admin' => {
# 'struct' => 'datetime',
# 'doc' => 'date this user become a list admin',
# 'not_null' => 1,
# 'order' => 6,
#},
'date_epoch_admin' => {
'struct' => 'int(11)',
'doc' => 'date this user become a list admin',
'not_null' => 1,
'order' => 6,
'order' => 6.5,
},
'update_admin' => {
'struct' => 'datetime',
'doc' => 'last update timestamp',
'order' => 7,
# Obsoleted as of 6.2.25b.2. Use update_epoch_admin.
#'update_admin' => {
# 'struct' => 'datetime',
# 'doc' => 'last update timestamp',
# 'order' => 7,
#},
'update_epoch_admin' => {
'struct' => 'int(11)',
'doc' => 'last update time',
'order' => 7.5,
},
'reception_admin' => {
'struct' => 'varchar(20)',
Expand Down Expand Up @@ -1257,6 +1282,8 @@ Text with length up to 2^32 - 4 o.
=item datetime

Timestamp.
B<Deprecated> as of Sympa 6.2.25b.3.
Use C<int(11)> (Unix time) instead.

=item mediumblob

Expand Down
2 changes: 2 additions & 0 deletions src/lib/Sympa/DatabaseDriver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ This method was deprecated.

=item get_formatted_date ( { mode => $mode, target => $target } )

B<Deprecated> as of Sympa 6.2.25b.3.

I<Mandatory for SQL driver>.
Returns a character string corresponding to the expression to use in a query
involving a date.
Expand Down
15 changes: 2 additions & 13 deletions src/lib/Sympa/DatabaseDriver/MySQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,8 @@ sub get_substring_clause {
# DEPRECATED.
#sub get_limit_clause ( { rows_count => $rows, offset => $offset } );

sub get_formatted_date {
my $self = shift;
my $param = shift;
$log->syslog('debug', 'Building SQL date formatting');
if (lc($param->{'mode'}) eq 'read') {
return sprintf 'UNIX_TIMESTAMP(%s)', $param->{'target'};
} elsif (lc($param->{'mode'}) eq 'write') {
return sprintf 'FROM_UNIXTIME(%d)', $param->{'target'};
} else {
$log->syslog('err', "Unknown date format mode %s", $param->{'mode'});
return undef;
}
}
# DEPRECATED.
#sub get_formatted_date;

sub is_autoinc {
my $self = shift;
Expand Down
8 changes: 2 additions & 6 deletions src/lib/Sympa/DatabaseDriver/ODBC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ sub build_connect_string {
return 'DBI:ODBC:' . $self->{'db_name'};
}

sub get_formatted_date {
my $self = shift;
my $param = shift;

die 'Not yet implemented: This is required by Sympa';
}
# DEPRECATED. Never implemented.
#sub get_formatted_date;

sub translate_type {
my $self = shift;
Expand Down
21 changes: 2 additions & 19 deletions src/lib/Sympa/DatabaseDriver/Oracle.pm
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,8 @@ sub get_substring_clause {
#DEPRECATED.
#sub get_limit_clause ( { rows_count => $rows, offset => $offset } );

sub get_formatted_date {
my $self = shift;
my $param = shift;
$log->syslog('debug', 'Building SQL date formatting');
if (lc($param->{'mode'}) eq 'read') {
return
sprintf
q{((to_number(to_char(%s,'J')) - to_number(to_char(to_date('01/01/1970','dd/mm/yyyy'), 'J'))) * 86400) +to_number(to_char(%s,'SSSSS'))},
$param->{'target'}, $param->{'target'};
} elsif (lc($param->{'mode'}) eq 'write') {
return
sprintf
q{to_date(to_char(floor(%s/86400) + to_number(to_char(to_date('01/01/1970','dd/mm/yyyy'), 'J'))) || ':' ||to_char(mod(%s,86400)), 'J:SSSSS')},
$param->{'target'}, $param->{'target'};
} else {
$log->syslog('err', "Unknown date format mode %s", $param->{'mode'});
return undef;
}
}
#DEPRECATED.
#sub get_formatted_date;

sub is_autoinc {
my $self = shift;
Expand Down
16 changes: 2 additions & 14 deletions src/lib/Sympa/DatabaseDriver/PostgreSQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,8 @@ sub get_substring_clause {
# DEPRECATED.
#sub get_limit_clause ( { rows_count => $rows, offset => $offset } );

sub get_formatted_date {
my $self = shift;
my $param = shift;
$log->syslog('debug', 'Building SQL date formatting');
if (lc($param->{'mode'}) eq 'read') {
return sprintf 'date_part(\'epoch\',%s)', $param->{'target'};
} elsif (lc($param->{'mode'}) eq 'write') {
return sprintf '\'epoch\'::timestamp with time zone + \'%d sec\'',
$param->{'target'};
} else {
$log->syslog('err', "Unknown date format mode %s", $param->{'mode'});
return undef;
}
}
# DEPRECATED.
#sub get_formatted_date;

sub is_autoinc {
my $self = shift;
Expand Down
13 changes: 2 additions & 11 deletions src/lib/Sympa/DatabaseDriver/SQLite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,8 @@ sub get_substring_clause {
# DEPRECATED.
#sub get_limit_clause ( { rows_count => $rows, offset => $offset } );

sub get_formatted_date {
my $self = shift;
my $param = shift;
$log->syslog('debug', 'Building SQL date formatting');
if (lc($param->{'mode'}) eq 'read' or lc($param->{'mode'}) eq 'write') {
return $param->{'target'};
} else {
$log->syslog('err', "Unknown date format mode %s", $param->{'mode'});
return undef;
}
}
# DEPRECATED.
#sub get_formatted_date;

sub is_autoinc {
my $self = shift;
Expand Down
17 changes: 2 additions & 15 deletions src/lib/Sympa/DatabaseDriver/Sybase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,8 @@ sub get_substring_clause {
# DEPRECATED.
#sub get_limit_clause ( { rows_count => $rows, offset => $offset } );

sub get_formatted_date {
my $self = shift;
my $param = shift;
$log->syslog('debug', 'Building SQL date formatting');
if (lc($param->{'mode'}) eq 'read') {
return sprintf 'datediff(second, \'01/01/1970\',%s)',
$param->{'target'};
} elsif (lc($param->{'mode'}) eq 'write') {
return sprintf 'dateadd(second,%s,\'01/01/1970\')',
$param->{'target'};
} else {
$log->syslog('err', "Unknown date format mode %s", $param->{'mode'});
return undef;
}
}
# DEPRECATED.
#sub get_formatted_date;

sub is_autoinc {
my $self = shift;
Expand Down
Loading