Commit a8c60d9d authored by IKEDA Soji's avatar IKEDA Soji
Browse files

SDM: Field type "datetime" is no longer used. Deprecate it and use "int(11)"...

SDM: Field type "datetime" is no longer used.  Deprecate it and use "int(11)" (Unixo timestamp) instead.
parent a9fa0776
......@@ -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 {
......
......@@ -1282,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
......
......@@ -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.
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -1740,7 +1740,7 @@ sub upgrade {
SET date_epoch_subscriber = %s
WHERE date_subscriber IS NOT NULL AND
date_epoch_subscriber IS NULL},
$sdm->get_canonical_read_date('date_subscriber')
_get_canonical_read_date($sdm, 'date_subscriber')
)
);
$sdm->do_prepared_query(
......@@ -1749,7 +1749,7 @@ sub upgrade {
SET update_epoch_subscriber = %s
WHERE update_subscriber IS NOT NULL AND
update_epoch_subscriber IS NULL},
$sdm->get_canonical_read_date('update_subscriber')
_get_canonical_read_date($sdm, 'update_subscriber')
)
);
$log->syslog('notice', 'Upgrading admin_table.');
......@@ -1761,7 +1761,7 @@ sub upgrade {
SET date_epoch_admin = %s
WHERE date_admin IS NOT NULL AND
date_epoch_admin IS NULL},
$sdm->get_canonical_read_date('date_admin')
_get_canonical_read_date($sdm, 'date_admin')
)
);
$sdm->do_prepared_query(
......@@ -1770,7 +1770,7 @@ sub upgrade {
SET update_epoch_admin = %s
WHERE update_admin IS NOT NULL AND
update_epoch_admin IS NULL},
$sdm->get_canonical_read_date('update_admin')
_get_canonical_read_date($sdm, 'update_admin')
)
);
}
......@@ -2049,4 +2049,52 @@ sub save_web_tt2 {
return 1;
}
sub _get_canonical_read_date {
my $sdm = shift;
my $target = shift;
if ($sdm->isa('Sympa::DatabaseDriver::MySQL')) {
return sprintf 'UNIX_TIMESTAMP(%s)', $target;
} elsif ($sdm->isa('Sympa::DatabaseDriver::Oracle')) {
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'))},
$target, $target;
} elsif ($sdm->isa('Sympa::DatabaseDriver::PostgreSQL')) {
return sprintf 'date_part(\'epoch\',%s)', $target;
} elsif ($sdm->isa('Sympa::DatabaseDriver::SQLite')) {
return $target;
} elsif ($sdm->isa('Sympa::DatabaseDriver::Sybase')) {
return sprintf 'datediff(second, \'01/01/1970\',%s)', $target;
} else {
# Unknown driver
return $target;
}
}
# No yet used.
sub _get_cacnonical_write_date {
my $sdm = shift;
my $target = shift;
if ($sdm->isa('Sympa::DatabaseDriver::MySQL')) {
return sprintf 'FROM_UNIXTIME(%d)', $target;
} elsif ($sdm->isa('Sympa::DatabaseDriver::Oracle')) {
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')},
$target, $target;
} elsif ($sdm->isa('Sympa::DatabaseDriver::PostgreSQL')) {
return sprintf '\'epoch\'::timestamp with time zone + \'%d sec\'',
$target;
} elsif ($sdm->isa('Sympa::DatabaseDriver::SQLite')) {
return $target;
} elsif ($sdm->isa('Sympa::DatabaseDriver::Sybase')) {
return sprintf 'dateadd(second,%s,\'01/01/1970\')', $target;
} else {
# Unknown driver
return $target;
}
}
1;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment