From 691fb16d30ae37e53201549332a39c2d072539ed Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 25 Feb 2019 12:39:19 +0000 Subject: [PATCH] Bug 22368: (QA follow-up) Switch to using foreign_key_exists Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall --- .../data/mysql/atomicupdate/bug_22368.perl | 39 ++++--------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug_22368.perl b/installer/data/mysql/atomicupdate/bug_22368.perl index f158556e40..40c6edfb8d 100644 --- a/installer/data/mysql/atomicupdate/bug_22368.perl +++ b/installer/data/mysql/atomicupdate/bug_22368.perl @@ -2,11 +2,7 @@ $DBversion = 'XXX'; # will be replaced by the RM if ( CheckVersion($DBversion) ) { # Add constraint for suggestedby - my $sth = $dbh->prepare( -q|SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='suggestions_ibfk_suggestedby'| - ); - $sth->execute; - unless ( $sth->fetchrow_hashref ) { + unless( foreign_key_exists( 'suggestions', 'suggestions_ibfk_suggestedby' ) ) { $dbh->do("ALTER TABLE suggestions CHANGE COLUMN suggestedby suggestedby INT(11) NULL DEFAULT NULL;"); $dbh->do( "UPDATE suggestions SET suggestedby = NULL where suggestedby NOT IN (SELECT borrowernumber FROM borrowers)" @@ -17,11 +13,7 @@ q|SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='sugg } # Add constraint for managedby - $sth = $dbh->prepare( -q|SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='suggestions_ibfk_managedby'| - ); - $sth->execute; - unless ( $sth->fetchrow_hashref ) { + unless( foreign_key_exists( 'suggestions', 'suggestions_ibfk_managedby' ) ) { $dbh->do( "UPDATE suggestions SET managedby = NULL where managedby NOT IN (SELECT borrowernumber FROM borrowers)" ); @@ -31,11 +23,7 @@ q|SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='sugg } # Add constraint for acceptedby - $sth = $dbh->prepare( -q|SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='suggestions_ibfk_acceptedby'| - ); - $sth->execute; - unless ( $sth->fetchrow_hashref ) { + unless( foreign_key_exists( 'suggestions', 'suggestions_ibfk_acceptedby' ) ) { $dbh->do( "UPDATE suggestions SET acceptedby = NULL where acceptedby NOT IN (SELECT borrowernumber FROM borrowers)" ); @@ -45,11 +33,7 @@ q|SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='sugg } # Add constraint for rejectedby - $sth = $dbh->prepare( -q|SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='suggestions_ibfk_rejectedby'| - ); - $sth->execute; - unless ( $sth->fetchrow_hashref ) { + unless( foreign_key_exists( 'suggestions', 'suggestions_ibfk_rejectedby' ) ) { $dbh->do( "UPDATE suggestions SET rejectedby = NULL where rejectedby NOT IN (SELECT borrowernumber FROM borrowers)" ); @@ -59,11 +43,7 @@ q|SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='sugg } # Add constraint for biblionumber - $sth = $dbh->prepare( -q|SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='suggestions_ibfk_biblionumber'| - ); - $sth->execute; - unless ( $sth->fetchrow_hashref ) { + unless( foreign_key_exists( 'suggestions', 'suggestions_ibfk_biblionumber' ) ) { $dbh->do( "UPDATE suggestions SET biblionumber = NULL where biblionumber NOT IN (SELECT biblionumber FROM biblio)" ); @@ -73,11 +53,7 @@ q|SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='sugg } # Add constraint for branchcode - $sth = $dbh->prepare( -q|SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='suggestions_ibfk_branchcode'| - ); - $sth->execute; - unless ( $sth->fetchrow_hashref ) { + unless( foreign_key_exists( 'suggestions', 'suggestions_ibfk_branchcode' ) ) { $dbh->do( "UPDATE suggestions SET branchcode = NULL where branchcode NOT IN (SELECT branchcode FROM branches)" ); @@ -87,6 +63,5 @@ q|SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='sugg } SetVersion($DBversion); - print -"Upgrade to $DBversion done (Bug 22368 - Add missing constraints to suggestions)\n"; + print "Upgrade to $DBversion done (Bug 22368 - Add missing constraints to suggestions)\n"; } -- 2.17.2 (Apple Git-113)