Re-add EnsureExists signature to fix compat with old plugins

Fixes #862
This commit is contained in:
Lucas Nicodemus 2015-02-22 08:43:12 -07:00
parent 0adcf32e3f
commit 04145a4aca
11 changed files with 33 additions and 11 deletions

2
TShockAPI/DB/BanManager.cs Normal file → Executable file
View file

@ -46,7 +46,7 @@ namespace TShockAPI.DB
: new MysqlQueryCreator());
try
{
creator.EnsureExists(table);
creator.EnsureTableStructure(table);
}
catch (DllNotFoundException)
{

View file

@ -57,7 +57,7 @@ namespace TShockAPI.DB
db.GetSqlType() == SqlType.Sqlite
? (IQueryBuilder) new SqliteQueryCreator()
: new MysqlQueryCreator());
creator.EnsureExists(table);
creator.EnsureTableStructure(table);
}
public PlayerData GetPlayerData(TSPlayer player, int acctid)

2
TShockAPI/DB/GroupManager.cs Normal file → Executable file
View file

@ -47,7 +47,7 @@ namespace TShockAPI.DB
db.GetSqlType() == SqlType.Sqlite
? (IQueryBuilder) new SqliteQueryCreator()
: new MysqlQueryCreator());
if (creator.EnsureExists(table))
if (creator.EnsureTableStructure(table))
{
// Add default groups if they don't exist
AddDefaultGroup("guest", "",

2
TShockAPI/DB/ItemManager.cs Normal file → Executable file
View file

@ -41,7 +41,7 @@ namespace TShockAPI.DB
db.GetSqlType() == SqlType.Sqlite
? (IQueryBuilder) new SqliteQueryCreator()
: new MysqlQueryCreator());
creator.EnsureExists(table);
creator.EnsureTableStructure(table);
UpdateItemBans();
}

2
TShockAPI/DB/ProjectileManager.cs Normal file → Executable file
View file

@ -41,7 +41,7 @@ namespace TShockAPI.DB
db.GetSqlType() == SqlType.Sqlite
? (IQueryBuilder) new SqliteQueryCreator()
: new MysqlQueryCreator());
creator.EnsureExists(table);
creator.EnsureTableStructure(table);
UpdateBans();
}

2
TShockAPI/DB/RegionManager.cs Normal file → Executable file
View file

@ -55,7 +55,7 @@ namespace TShockAPI.DB
db.GetSqlType() == SqlType.Sqlite
? (IQueryBuilder) new SqliteQueryCreator()
: new MysqlQueryCreator());
creator.EnsureExists(table);
creator.EnsureTableStructure(table);
}
/// <summary>

2
TShockAPI/DB/RememberedPosManager.cs Normal file → Executable file
View file

@ -42,7 +42,7 @@ namespace TShockAPI.DB
db.GetSqlType() == SqlType.Sqlite
? (IQueryBuilder) new SqliteQueryCreator()
: new MysqlQueryCreator());
creator.EnsureExists(table);
creator.EnsureTableStructure(table);
}
public Vector2 CheckLeavePos(string name)

24
TShockAPI/DB/SqlTable.cs Normal file → Executable file
View file

@ -53,7 +53,7 @@ namespace TShockAPI.DB
}
// Returns true if the table was created; false if it was not.
public bool EnsureExists(SqlTable table)
public bool EnsureTableStructure(SqlTable table)
{
var columns = GetColumns(table);
if (columns.Count > 0)
@ -72,6 +72,28 @@ namespace TShockAPI.DB
return false;
}
/// <summary>
/// Ensures a table exists and that its structure is correct
/// </summary>
/// <param name="table">The table name</param>
[Obsolete("This method will be replaced by EnsureTableExists.")]
public void EnsureExists(SqlTable table)
{
var columns = GetColumns(table);
if (columns.Count > 0)
{
if (!table.Columns.All(c => columns.Contains(c.Name)) || !columns.All(c => table.Columns.Any(c2 => c2.Name == c)))
{
var from = new SqlTable(table.Name, columns.Select(s => new SqlColumn(s, MySqlDbType.String)).ToList());
database.Query(creator.AlterTable(from, table));
}
}
else
{
database.Query(creator.CreateTable(table));
}
}
public List<string> GetColumns(SqlTable table)
{
var ret = new List<string>();

2
TShockAPI/DB/TileManager.cs Normal file → Executable file
View file

@ -41,7 +41,7 @@ namespace TShockAPI.DB
db.GetSqlType() == SqlType.Sqlite
? (IQueryBuilder)new SqliteQueryCreator()
: new MysqlQueryCreator());
creator.EnsureExists(table);
creator.EnsureTableStructure(table);
UpdateBans();
}

View file

@ -48,7 +48,7 @@ namespace TShockAPI.DB
db.GetSqlType() == SqlType.Sqlite
? (IQueryBuilder) new SqliteQueryCreator()
: new MysqlQueryCreator());
creator.EnsureExists(table);
creator.EnsureTableStructure(table);
}
/// <summary>

2
TShockAPI/DB/WarpsManager.cs Normal file → Executable file
View file

@ -51,7 +51,7 @@ namespace TShockAPI.DB
db.GetSqlType() == SqlType.Sqlite
? (IQueryBuilder) new SqliteQueryCreator()
: new MysqlQueryCreator());
creator.EnsureExists(table);
creator.EnsureTableStructure(table);
}
/// <summary>