From 0871a963994efea5b908b5f238e70586f4b1b5e7 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Sat, 12 Jan 2013 00:34:52 -0500 Subject: [PATCH] Fix SQL syntax issue. --- .../com/gmail/nossr50/datatypes/DatabaseUpdate.java | 3 ++- src/main/java/com/gmail/nossr50/util/Database.java | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/datatypes/DatabaseUpdate.java b/src/main/java/com/gmail/nossr50/datatypes/DatabaseUpdate.java index 60ee23b22..439d2e7f8 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/DatabaseUpdate.java +++ b/src/main/java/com/gmail/nossr50/datatypes/DatabaseUpdate.java @@ -2,5 +2,6 @@ package com.gmail.nossr50.datatypes; public enum DatabaseUpdate { FISHING, - BLAST_MINING; + BLAST_MINING, + CASCADE_DELETE; } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/util/Database.java b/src/main/java/com/gmail/nossr50/util/Database.java index 9fb8993d2..a9b2be22d 100644 --- a/src/main/java/com/gmail/nossr50/util/Database.java +++ b/src/main/java/com/gmail/nossr50/util/Database.java @@ -87,7 +87,7 @@ public class Database { + "`user_id` int(10) unsigned NOT NULL," + "`hudtype` varchar(50) NOT NULL DEFAULT 'STANDARD'," + "PRIMARY KEY (`user_id`)" - + "FOREIGN KEY (`user_id`) REFERENCES `" + tablePrefix + "users`)" + + "FOREIGN KEY (`user_id`) REFERENCES `" + tablePrefix + "users`" + "ON DELETE CASCADE) ENGINE=MyISAM DEFAULT CHARSET=latin1;"); write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "cooldowns` (" + "`user_id` int(10) unsigned NOT NULL," @@ -104,7 +104,7 @@ public class Database { + "`acrobatics` int(32) unsigned NOT NULL DEFAULT '0'," + "`blast_mining` int(32) unsigned NOT NULL DEFAULT '0'," + "PRIMARY KEY (`user_id`)" - + "FOREIGN KEY (`user_id`) REFERENCES `" + tablePrefix + "users`)" + + "FOREIGN KEY (`user_id`) REFERENCES `" + tablePrefix + "users`" + "ON DELETE CASCADE) ENGINE=MyISAM DEFAULT CHARSET=latin1;"); write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "skills` (" + "`user_id` int(10) unsigned NOT NULL," @@ -120,7 +120,7 @@ public class Database { + "`axes` int(10) unsigned NOT NULL DEFAULT '0'," + "`acrobatics` int(10) unsigned NOT NULL DEFAULT '0'," + "PRIMARY KEY (`user_id`)" - + "FOREIGN KEY (`user_id`) REFERENCES `" + tablePrefix + "users`)" + + "FOREIGN KEY (`user_id`) REFERENCES `" + tablePrefix + "users`" + "ON DELETE CASCADE) ENGINE=MyISAM DEFAULT CHARSET=latin1;"); write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "experience` (" + "`user_id` int(10) unsigned NOT NULL," @@ -136,11 +136,12 @@ public class Database { + "`axes` int(10) unsigned NOT NULL DEFAULT '0'," + "`acrobatics` int(10) unsigned NOT NULL DEFAULT '0'," + "PRIMARY KEY (`user_id`)" - + "FOREIGN KEY (`user_id`) REFERENCES `" + tablePrefix + "users`)" + + "FOREIGN KEY (`user_id`) REFERENCES `" + tablePrefix + "users`" + "ON DELETE CASCADE) ENGINE=MyISAM DEFAULT CHARSET=latin1;"); checkDatabaseStructure(DatabaseUpdate.FISHING); checkDatabaseStructure(DatabaseUpdate.BLAST_MINING); + checkDatabaseStructure(DatabaseUpdate.CASCADE_DELETE); } /** @@ -200,7 +201,7 @@ public class Database { } } finally { if (resultSet != null) { - try { + try { resultSet.close(); } catch (SQLException e) { // Ignore the error, we're leaving