Delete a bunch of cruft that has gone unmaintained for too long.
Fix warps to have an auto-increment primary key column, and unique on name/WorldID Same for regions. Changed SqliteTableCreator to do proper unique syntax.
This commit is contained in:
parent
34b268f1db
commit
1c7fe908b6
19 changed files with 15 additions and 2321 deletions
|
|
@ -44,10 +44,15 @@ namespace TShockAPI.DB
|
|||
var columns =
|
||||
table.Columns.Select(
|
||||
c =>
|
||||
"'{0}' {1} {2} {3} {4} {5}".SFormat(c.Name, DbTypeToString(c.Type, c.Length), c.Primary ? "PRIMARY KEY" : "",
|
||||
c.AutoIncrement ? "AUTOINCREMENT" : "", c.NotNull ? "NOT NULL" : "",
|
||||
c.Unique ? "UNIQUE" : ""));
|
||||
return "CREATE TABLE {0} ({1})".SFormat(EscapeTableName(table.Name), string.Join(", ", columns));
|
||||
"'{0}' {1} {2} {3} {4}".SFormat(c.Name,
|
||||
DbTypeToString(c.Type, c.Length),
|
||||
c.Primary ? "PRIMARY KEY" : "",
|
||||
c.AutoIncrement ? "AUTOINCREMENT" : "",
|
||||
c.NotNull ? "NOT NULL" : ""));
|
||||
var uniques = table.Columns.Where(c => c.Unique).Select(c => c.Name);
|
||||
return "CREATE TABLE {0} ({1} {2})".SFormat(EscapeTableName(table.Name),
|
||||
string.Join(", ", columns),
|
||||
uniques.Count() > 0 ? ", UNIQUE({0})".SFormat(string.Join(", ", uniques)) : "");
|
||||
}
|
||||
|
||||
public override string RenameTable(string from, string to)
|
||||
|
|
|
|||
|
|
@ -38,12 +38,13 @@ namespace TShockAPI.DB
|
|||
{
|
||||
database = db;
|
||||
var table = new SqlTable("Regions",
|
||||
new SqlColumn("Id", MySqlDbType.Int32) {Primary = true, AutoIncrement = true},
|
||||
new SqlColumn("X1", MySqlDbType.Int32),
|
||||
new SqlColumn("Y1", MySqlDbType.Int32),
|
||||
new SqlColumn("width", MySqlDbType.Int32),
|
||||
new SqlColumn("height", MySqlDbType.Int32),
|
||||
new SqlColumn("RegionName", MySqlDbType.VarChar, 50) {Primary = true},
|
||||
new SqlColumn("WorldID", MySqlDbType.Text),
|
||||
new SqlColumn("RegionName", MySqlDbType.VarChar, 50) {Unique = true},
|
||||
new SqlColumn("WorldID", MySqlDbType.Text) {Unique = true},
|
||||
new SqlColumn("UserIds", MySqlDbType.Text),
|
||||
new SqlColumn("Protected", MySqlDbType.Int32),
|
||||
new SqlColumn("Groups", MySqlDbType.Text),
|
||||
|
|
@ -114,53 +115,6 @@ namespace TShockAPI.DB
|
|||
}
|
||||
}
|
||||
|
||||
public void ReloadForUnitTest(String n)
|
||||
{
|
||||
using (var reader = database.QueryReader("SELECT * FROM Regions WHERE WorldID=@0", n))
|
||||
{
|
||||
Regions.Clear();
|
||||
while (reader.Read())
|
||||
{
|
||||
int X1 = reader.Get<int>("X1");
|
||||
int Y1 = reader.Get<int>("Y1");
|
||||
int height = reader.Get<int>("height");
|
||||
int width = reader.Get<int>("width");
|
||||
int Protected = reader.Get<int>("Protected");
|
||||
string MergedIDs = reader.Get<string>("UserIds");
|
||||
string name = reader.Get<string>("RegionName");
|
||||
string[] SplitIDs = MergedIDs.Split(',');
|
||||
string owner = reader.Get<string>("Owner");
|
||||
string groups = reader.Get<string>("Groups");
|
||||
int z = reader.Get<int>("Z");
|
||||
|
||||
Region r = new Region(new Rectangle(X1, Y1, width, height), name, owner, Protected != 0, Main.worldID.ToString(), z);
|
||||
r.SetAllowedGroups(groups);
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < SplitIDs.Length; i++)
|
||||
{
|
||||
int id;
|
||||
|
||||
if (Int32.TryParse(SplitIDs[i], out id)) // if unparsable, it's not an int, so silently skip
|
||||
r.AllowedIDs.Add(id);
|
||||
else if (SplitIDs[i] == "") // Split gotcha, can return an empty string with certain conditions
|
||||
// but we only want to let the user know if it's really a nonparsable integer.
|
||||
Log.Warn("UnitTest: One of your UserIDs is not a usable integer: " + SplitIDs[i]);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error("Your database contains invalid UserIDs (they should be ints).");
|
||||
Log.Error("A lot of things will fail because of this. You must manually delete and re-create the allowed field.");
|
||||
Log.Error(e.Message);
|
||||
Log.Error(e.StackTrace);
|
||||
}
|
||||
|
||||
Regions.Add(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool AddRegion(int tx, int ty, int width, int height, string regionname, string owner, string worldid, int z = 0)
|
||||
{
|
||||
if (GetRegionByName(regionname) != null)
|
||||
|
|
@ -469,16 +423,6 @@ namespace TShockAPI.DB
|
|||
return Regions.FirstOrDefault(r => r.Name.Equals(name) && r.WorldID == Main.worldID.ToString());
|
||||
}
|
||||
|
||||
public Region ZacksGetRegionByName(String name)
|
||||
{
|
||||
foreach (Region r in Regions)
|
||||
{
|
||||
if (r.Name.Equals(name))
|
||||
return r;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool ChangeOwner(string regionName, string newOwner)
|
||||
{
|
||||
var region = GetRegionByName(regionName);
|
||||
|
|
|
|||
|
|
@ -40,10 +40,11 @@ namespace TShockAPI.DB
|
|||
database = db;
|
||||
|
||||
var table = new SqlTable("Warps",
|
||||
new SqlColumn("WarpName", MySqlDbType.VarChar, 50) {Primary = true},
|
||||
new SqlColumn("Id", MySqlDbType.Int32){Primary = true, AutoIncrement = true},
|
||||
new SqlColumn("WarpName", MySqlDbType.VarChar, 50) {Unique = true},
|
||||
new SqlColumn("X", MySqlDbType.Int32),
|
||||
new SqlColumn("Y", MySqlDbType.Int32),
|
||||
new SqlColumn("WorldID", MySqlDbType.Text),
|
||||
new SqlColumn("WorldID", MySqlDbType.Text) {Unique = true},
|
||||
new SqlColumn("Private", MySqlDbType.Text)
|
||||
);
|
||||
var creator = new SqlTableCreator(db,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue