From 77d9cc39de9d62a7644334654fbbc0dc5c8a3675 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 Content-Type: text/plain; charset=utf-8 Signed-off-by: Martin Renvoize Signed-off-by: Marcel de Rooy --- 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.11.0