From 796ba0d899cc0192df8f13ff2a69b4fbc5a2bd7b Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 4 Jan 2018 17:16:43 -0500 Subject: [PATCH] revert to using the mysql client to do updates. We need it for delemiter changes when adding triggers --- scripts/zmupdate.pl.in | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/scripts/zmupdate.pl.in b/scripts/zmupdate.pl.in index bcb12d3ce..5e7b72411 100644 --- a/scripts/zmupdate.pl.in +++ b/scripts/zmupdate.pl.in @@ -932,17 +932,44 @@ sub patchDB { my $dbh = shift; my $version = shift; - my $file = ( $updateDir ? $updateDir : $Config{ZM_PATH_DATA}.'/db' ) . "/zm_update-$version.sql"; + my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ ); + my $command = 'mysql'; + if ( defined($portOrSocket) ) { + if ( $portOrSocket =~ /^\// ) { + $command .= ' -S'.$portOrSocket; + } else { + $command .= ' -h'.$host.' -P'.$portOrSocket; + } + } else { + $command .= ' -h'.$host; + } + if ( $dbUser ) { + $command .= ' -u'.$dbUser; + $command .= ' -p"'.$dbPass.'"' if $dbPass; + } + $command .= ' '.$Config{ZM_DB_NAME}.' < '; + if ( $updateDir ) { + $command .= $updateDir; + } else { + $command .= $Config{ZM_PATH_DATA}.'/db'; + } + $command .= '/zm_update-'.$version.'.sql'; - open( my $fh, '<', $file ) or die "Unable to open $file $!"; - $/ = undef; - my $sql = <$fh>; - close $fh; - $dbh->do($sql) or die $dbh->errstr(); + print( "Executing '$command'\n" ) if ( logDebugging() ); + my $output = qx($command); + my $status = $? >> 8; + if ( $status || logDebugging() ) { + chomp( $output ); + print( "Output: $output\n" ); + } + if ( $status ) { + die( "Command '$command' exited with status: $status\n" ); + } print( "\nDatabase successfully upgraded to version $version.\n" ); - $sql = "update Config set Value = ? where Name = 'ZM_DYN_DB_VERSION'"; + my $sql = "update Config set Value = ? where Name = 'ZM_DYN_DB_VERSION'"; my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); my $res = $sth->execute( $version ) or die( "Can't execute: ".$sth->errstr() ); + $sth->finish(); } sub migratePaths {