Unverified Commit 648f434f authored by IKEDA Soji's avatar IKEDA Soji Committed by GitHub
Browse files

Merge pull request #1254 from ikedas/issue-1252 by ikedas

MySQL: probe_db() cannot update int fields with MySQL 8.0.17 or later (#1252)
parents 097df70b 50711acd
...@@ -487,6 +487,31 @@ sub error { ...@@ -487,6 +487,31 @@ sub error {
return undef; return undef;
} }
# Old name: Sympa::DatabaseManager::_check_db_field_type().
sub is_sufficient_field_type {
my $self = shift;
my $required = shift;
my $effective = shift;
my ($required_type, $required_size, $effective_type, $effective_size);
if ($required =~ /^(\w+)(\((\d+)\))?$/) {
($required_type, $required_size) = ($1, $3);
}
if ($effective =~ /^(\w+)(\((\d+)\))?$/) {
($effective_type, $effective_size) = ($1, $3);
}
if ( ($effective_type // '') eq ($required_type // '')
and (not defined $required_size or $effective_size >= $required_size))
{
return 1;
}
return 0;
}
sub set_persistent { sub set_persistent {
my $self = shift; my $self = shift;
my $flag = shift; my $flag = shift;
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, # Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites # 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER # Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
# Copyright 2018 The Sympa Community. See the AUTHORS.md file at the # Copyright 2018, 2021 The Sympa Community. See the
# top-level directory of this distribution and at # AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>. # <https://github.com/sympa-community/sympa.git>.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
...@@ -210,6 +210,32 @@ Returns: ...@@ -210,6 +210,32 @@ Returns:
True if the field is an auto-increment field, false otherwise True if the field is an auto-increment field, false otherwise
=item is_sufficient_field_type ( $required, $actual )
I<Overridable>, I<only for SQL driver>.
Checks if database field type is sufficient.
Parameters:
=over
=item $required
Required field type.
=item $actual
Actual field type.
=back
Returns:
The true value if actual field type is appropriate AND size is equal to or
greater than required size.
This method was added on Sympa 6.2.67b.1.
=item set_autoinc ( { table => $table, field => $field } ) =item set_autoinc ( { table => $table, field => $field } )
I<Required to update database structure>. I<Required to update database structure>.
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, # Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites # 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER # Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
# Copyright 2018, 2020 The Sympa Community. See the AUTHORS.md # Copyright 2018, 2020, 2021 The Sympa Community. See the
# file at the top-level directory of this distribution and at # AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>. # <https://github.com/sympa-community/sympa.git>.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
...@@ -335,6 +335,20 @@ sub get_primary_key { ...@@ -335,6 +335,20 @@ sub get_primary_key {
return \%found_keys; return \%found_keys;
} }
sub is_sufficient_field_type {
my $self = shift;
my $required = shift;
my $actual = shift;
# As of MySQL 8.0.17, the display width attribute is deprecated for
# integer data types (MeriaDB has not).
if ($required =~ /\A((?:tiny|small|medium|big)?int)(?:[(]\d+[)])?\z/
and $actual eq $1) {
return 1;
}
return $self->SUPER::is_sufficient_field_type($required, $actual);
}
sub unset_primary_key { sub unset_primary_key {
my $self = shift; my $self = shift;
my $param = shift; my $param = shift;
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, # Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites # 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER # Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
# Copyright 2021 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -29,11 +32,9 @@ use warnings; ...@@ -29,11 +32,9 @@ use warnings;
use Sympa; use Sympa;
use Conf; use Conf;
use Sympa::Constants;
use Sympa::Database; use Sympa::Database;
use Sympa::DatabaseDescription; use Sympa::DatabaseDescription;
use Sympa::Log; use Sympa::Log;
use Sympa::Tools::Data;
my $log = Sympa::Log->instance; my $log = Sympa::Log->instance;
...@@ -361,9 +362,9 @@ sub _check_fields { ...@@ -361,9 +362,9 @@ sub _check_fields {
## Change DB types if different and if update_db_types enabled ## Change DB types if different and if update_db_types enabled
if ($may_update) { if ($may_update) {
unless ( unless (
_check_db_field_type( $sdm->is_sufficient_field_type(
effective_format => $real_struct{$t}{$f}, $db_struct->{$t}->{$f},
required_format => $db_struct->{$t}->{$f} $real_struct{$t}{$f}
) )
) { ) {
push @{$report_ref}, push @{$report_ref},
...@@ -693,30 +694,8 @@ sub _check_key { ...@@ -693,30 +694,8 @@ sub _check_key {
return $result; return $result;
} }
## Compare required DB field type # Moved: Use Sympa::Database::is_sufficient_field_type().
## Input : required_format, effective_format #sub _check_db_field_type;
## Output : return 1 if field type is appropriate AND size >= required size
sub _check_db_field_type {
my %param = @_;
my ($required_type, $required_size, $effective_type, $effective_size);
if ($param{'required_format'} =~ /^(\w+)(\((\d+)\))?$/) {
($required_type, $required_size) = ($1, $3);
}
if ($param{'effective_format'} =~ /^(\w+)(\((\d+)\))?$/) {
($effective_type, $effective_size) = ($1, $3);
}
if (Sympa::Tools::Data::smart_eq($effective_type, $required_type)
and (not defined $required_size or $effective_size >= $required_size))
{
return 1;
}
return 0;
}
1; 1;
__END__ __END__
......
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