Do a Database.TableExists check when deleting and renaming level portals/mbs/zone tables.

This commit is contained in:
UnknownShadow200 2016-08-23 18:29:07 +10:00
parent 5ace7cd08c
commit 6e1dcc72f1
2 changed files with 22 additions and 20 deletions

View File

@ -57,19 +57,18 @@ namespace MCGalaxy {
//safe against SQL injections because foundLevel is being checked and,
//newName is being split and partly checked on illegal characters reserved for Windows.
if (Server.useMySQL)
Database.Execute(String.Format("RENAME TABLE `Block{0}` TO `Block{1}`, " +
"`Portals{0}` TO `Portals{1}`, " +
"`Messages{0}` TO `Messages{1}`, " +
"`Zone{0}` TO `Zone{1}`", src, dst));
else {
using (BulkTransaction helper = SQLiteBulkTransaction.Create()) { // ensures that it's either all work, or none work.
helper.Execute(String.Format("ALTER TABLE `Block{0}` RENAME TO `Block{1}`", src, dst));
helper.Execute(String.Format("ALTER TABLE `Portals{0}` RENAME TO `Portals{1}`", src, dst));
helper.Execute(String.Format("ALTER TABLE `Messages{0}` RENAME TO `Messages{1}`", src, dst));
helper.Execute(String.Format("ALTER TABLE `Zone{0}` RENAME TO `Zone{1}`", src, dst));
helper.Commit();
}
string syntax = Server.useMySQL
? "RENAME TABLE `{2}{0}` TO `{2}{1}`" : "ALTER TABLE `{2}{0}` RENAME TO `{2}{1}`";
Database.Execute(String.Format(syntax, src, dst, "Blocks"));
object locker = ThreadSafeCache.DBCache.Get(src);
lock (locker) {
if (Database.TableExists("Portals" + src))
Database.Execute(String.Format(syntax, src, dst, "Portals"));
if (Database.TableExists("Messages" + src))
Database.Execute(String.Format(syntax, src, dst, "Messages"));
if (Database.TableExists("Zone" + src))
Database.Execute(String.Format(syntax, src, dst, "Zone"));
}
}
@ -128,8 +127,11 @@ namespace MCGalaxy {
Database.Execute("DROP TABLE `Block" + name + "`");
object locker = ThreadSafeCache.DBCache.Get(name);
lock (locker) {
if (Database.TableExists("Portals" + name))
Database.Execute("DROP TABLE `Portals" + name + "`");
if (Database.TableExists("Messages" + name))
Database.Execute("DROP TABLE `Messages" + name + "`");
if (Database.TableExists("Zone" + name))
Database.Execute("DROP TABLE `Zone" + name + "`");
}
}

View File

@ -66,7 +66,7 @@ namespace MCGalaxy.BlockPhysics {
public bool HasWait {
get { return (Raw & TypeBitsMask) == Wait
|| ((Raw >> 3) & TypeBitsMask) == Wait);
|| ((Raw >> 3) & TypeBitsMask) == Wait;
}
}