From 5efe8b6da41fe373fdf5917bb0dc0cdfba0e9f64 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 24 Mar 2020 16:22:33 +0100 Subject: [PATCH] Bug 18177: Do not remove columns if at least one value exists --- installer/data/mysql/atomicupdate/bug_18177.perl | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug_18177.perl b/installer/data/mysql/atomicupdate/bug_18177.perl index 0426fda963..61b0e5e543 100644 --- a/installer/data/mysql/atomicupdate/bug_18177.perl +++ b/installer/data/mysql/atomicupdate/bug_18177.perl @@ -3,10 +3,19 @@ if( CheckVersion( $DBversion ) ) { for my $column ( qw(othersupplier booksellerfax booksellerurl bookselleremail currency) ) { if( column_exists( 'aqbooksellers', $column ) ) { - $dbh->do(qq| - ALTER TABLE aqbooksellers - DROP COLUMN $column + my ($count) = $dbh->selectrow_array(qq| + SELECT COUNT(*) + FROM aqbooksellers + WHERE $column IS NOT NULL AND $column <> "" |); + if ( $count ) { + warn "Warning - Cannot remove column aqbooksellers.$column. At least one value exists"; + } else { + $dbh->do(qq| + ALTER TABLE aqbooksellers + DROP COLUMN $column + |); + } } } -- 2.20.1