[otrs-cvs] otrs/Kernel/System/DB mysql.pm,1.61,1.62

"CVS commits notifications of OTRS.org" <[email protected]>
Newsgroups gmane.comp.otrs.cvs
Message-ID <[email protected]>
Comments:
Update of /home/cvs/otrs/Kernel/System/DB
In directory lancelot:/tmp/cvs-serv3456/Kernel/System/DB

Modified Files:
	mysql.pm 
Log Message:
Fixed bug#9135 - Can't upgrade databases that have been changed from MyISAM > InnoDB.

Author: mg

Index: mysql.pm
===================================================================
RCS file: /home/cvs/otrs/Kernel/System/DB/mysql.pm,v
retrieving revision 1.61
retrieving revision 1.62
diff -2 -u -d -r1.61 -r1.62
--- mysql.pm	20 Nov 2012 15:45:33 -0000	1.61
+++ mysql.pm	7 Feb 2013 10:08:33 -0000	1.62
@@ -1,5 +1,5 @@
 # --
 # Kernel/System/DB/mysql.pm - mysql database backend
-# Copyright (C) 2001-2012 OTRS AG, http://otrs.org/
+# Copyright (C) 2001-2013 OTRS AG, http://otrs.org/
 # --
 # $Id$
@@ -589,7 +589,21 @@
 
     # drop foreign key
-    my $SQL = "ALTER TABLE $Param{LocalTableName} DROP FOREIGN KEY $ForeignKey";
+    my @SQL;
 
-    return ($SQL);
+    if ( $Self->{ConfigObject}->Get('Database::ShellOutput') ) {
+        push @SQL, $Self->{'DB::Comment'}
+            . ' MySQL does not create foreign key constraints in MyISAM. Dropping nonexisting constraints in MyISAM works just fine.';
+        push @SQL, $Self->{'DB::Comment'}
+            . ' However, if the table is converted to InnoDB, this will result in an error. Therefore, only drop constraints if they exist.';
+    }
+
+    push @SQL,
+        "SET \@FKExists := (SELECT COUNT(*) FROM information_schema.table_constraints WHERE table_schema = DATABASE() AND table_name = '$Param{LocalTableName}' AND constraint_name = '$ForeignKey')";
+    push @SQL,
+        "SET \@FKSQLStatement := IF( \@FKExists > 0, 'ALTER TABLE $Param{LocalTableName} DROP FOREIGN KEY $ForeignKey', 'SELECT ''INFO: Foreign key constraint $ForeignKey does not exist, skipping.''' )";
+    push @SQL, "PREPARE FKStatement FROM \@FKSQLStatement";
+    push @SQL, "EXECUTE FKStatement";
+
+    return @SQL;
 }
 
---------------------------------------------------------------------
OTRS mailing list: cvs-log - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/cvs-log
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/cvs-log
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.