From 4107082845e396fb3dff0cc762ec41c7cfc040ce Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 7 Nov 2018 11:01:49 -0500 Subject: [PATCH] Don't delete default states if there are none --- scripts/zmpkg.pl.in | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/zmpkg.pl.in b/scripts/zmpkg.pl.in index b29235f65..2d6593619 100644 --- a/scripts/zmpkg.pl.in +++ b/scripts/zmpkg.pl.in @@ -315,17 +315,19 @@ sub isActiveSanityCheck { if ( $sth->rows != 1 ) { # PP - no row, or too many rows. Either case is an error Info( 'Fixing States table - either no default state or duplicate default states' ); - $sql = "DELETE FROM States WHERE Name='default'"; - $sth = $dbh->prepare_cached( $sql ) - or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - $res = $sth->execute() - or Fatal( "Can't execute: ".$sth->errstr() ); - $sql = q`"INSERT INTO States (Name,Definition,IsActive) VALUES ('default','','1');`; + if ( $sth->rows ) { + $sql = q`DELETE FROM States WHERE Name='default'`; + $sth = $dbh->prepare_cached( $sql ) + or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); + $res = $sth->execute() + or Fatal( "Can't execute: ".$sth->errstr() ); + } + $sql = q`INSERT INTO States (Name,Definition,IsActive) VALUES ('default','','1');`; $sth = $dbh->prepare_cached($sql) or Fatal("Can't prepare '$sql': ".$dbh->errstr()); $res = $sth->execute() or Fatal("Can't execute: ".$sth->errstr()); - } + } # PP - Now make sure no two states have IsActive=1 $sql = 'SELECT Name FROM States WHERE IsActive = 1';