Re-add EnsureExists signature to fix compat with old plugins
Fixes #862
This commit is contained in:
parent
0adcf32e3f
commit
04145a4aca
11 changed files with 33 additions and 11 deletions
2
TShockAPI/DB/BanManager.cs
Normal file → Executable file
2
TShockAPI/DB/BanManager.cs
Normal file → Executable file
|
|
@ -46,7 +46,7 @@ namespace TShockAPI.DB
|
||||||
: new MysqlQueryCreator());
|
: new MysqlQueryCreator());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
creator.EnsureExists(table);
|
creator.EnsureTableStructure(table);
|
||||||
}
|
}
|
||||||
catch (DllNotFoundException)
|
catch (DllNotFoundException)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ namespace TShockAPI.DB
|
||||||
db.GetSqlType() == SqlType.Sqlite
|
db.GetSqlType() == SqlType.Sqlite
|
||||||
? (IQueryBuilder) new SqliteQueryCreator()
|
? (IQueryBuilder) new SqliteQueryCreator()
|
||||||
: new MysqlQueryCreator());
|
: new MysqlQueryCreator());
|
||||||
creator.EnsureExists(table);
|
creator.EnsureTableStructure(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerData GetPlayerData(TSPlayer player, int acctid)
|
public PlayerData GetPlayerData(TSPlayer player, int acctid)
|
||||||
|
|
|
||||||
2
TShockAPI/DB/GroupManager.cs
Normal file → Executable file
2
TShockAPI/DB/GroupManager.cs
Normal file → Executable file
|
|
@ -47,7 +47,7 @@ namespace TShockAPI.DB
|
||||||
db.GetSqlType() == SqlType.Sqlite
|
db.GetSqlType() == SqlType.Sqlite
|
||||||
? (IQueryBuilder) new SqliteQueryCreator()
|
? (IQueryBuilder) new SqliteQueryCreator()
|
||||||
: new MysqlQueryCreator());
|
: new MysqlQueryCreator());
|
||||||
if (creator.EnsureExists(table))
|
if (creator.EnsureTableStructure(table))
|
||||||
{
|
{
|
||||||
// Add default groups if they don't exist
|
// Add default groups if they don't exist
|
||||||
AddDefaultGroup("guest", "",
|
AddDefaultGroup("guest", "",
|
||||||
|
|
|
||||||
2
TShockAPI/DB/ItemManager.cs
Normal file → Executable file
2
TShockAPI/DB/ItemManager.cs
Normal file → Executable file
|
|
@ -41,7 +41,7 @@ namespace TShockAPI.DB
|
||||||
db.GetSqlType() == SqlType.Sqlite
|
db.GetSqlType() == SqlType.Sqlite
|
||||||
? (IQueryBuilder) new SqliteQueryCreator()
|
? (IQueryBuilder) new SqliteQueryCreator()
|
||||||
: new MysqlQueryCreator());
|
: new MysqlQueryCreator());
|
||||||
creator.EnsureExists(table);
|
creator.EnsureTableStructure(table);
|
||||||
UpdateItemBans();
|
UpdateItemBans();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
2
TShockAPI/DB/ProjectileManager.cs
Normal file → Executable file
2
TShockAPI/DB/ProjectileManager.cs
Normal file → Executable file
|
|
@ -41,7 +41,7 @@ namespace TShockAPI.DB
|
||||||
db.GetSqlType() == SqlType.Sqlite
|
db.GetSqlType() == SqlType.Sqlite
|
||||||
? (IQueryBuilder) new SqliteQueryCreator()
|
? (IQueryBuilder) new SqliteQueryCreator()
|
||||||
: new MysqlQueryCreator());
|
: new MysqlQueryCreator());
|
||||||
creator.EnsureExists(table);
|
creator.EnsureTableStructure(table);
|
||||||
UpdateBans();
|
UpdateBans();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
2
TShockAPI/DB/RegionManager.cs
Normal file → Executable file
2
TShockAPI/DB/RegionManager.cs
Normal file → Executable file
|
|
@ -55,7 +55,7 @@ namespace TShockAPI.DB
|
||||||
db.GetSqlType() == SqlType.Sqlite
|
db.GetSqlType() == SqlType.Sqlite
|
||||||
? (IQueryBuilder) new SqliteQueryCreator()
|
? (IQueryBuilder) new SqliteQueryCreator()
|
||||||
: new MysqlQueryCreator());
|
: new MysqlQueryCreator());
|
||||||
creator.EnsureExists(table);
|
creator.EnsureTableStructure(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
2
TShockAPI/DB/RememberedPosManager.cs
Normal file → Executable file
2
TShockAPI/DB/RememberedPosManager.cs
Normal file → Executable file
|
|
@ -42,7 +42,7 @@ namespace TShockAPI.DB
|
||||||
db.GetSqlType() == SqlType.Sqlite
|
db.GetSqlType() == SqlType.Sqlite
|
||||||
? (IQueryBuilder) new SqliteQueryCreator()
|
? (IQueryBuilder) new SqliteQueryCreator()
|
||||||
: new MysqlQueryCreator());
|
: new MysqlQueryCreator());
|
||||||
creator.EnsureExists(table);
|
creator.EnsureTableStructure(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2 CheckLeavePos(string name)
|
public Vector2 CheckLeavePos(string name)
|
||||||
|
|
|
||||||
24
TShockAPI/DB/SqlTable.cs
Normal file → Executable file
24
TShockAPI/DB/SqlTable.cs
Normal file → Executable file
|
|
@ -53,7 +53,7 @@ namespace TShockAPI.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the table was created; false if it was not.
|
// 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);
|
var columns = GetColumns(table);
|
||||||
if (columns.Count > 0)
|
if (columns.Count > 0)
|
||||||
|
|
@ -72,6 +72,28 @@ namespace TShockAPI.DB
|
||||||
return false;
|
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)
|
public List<string> GetColumns(SqlTable table)
|
||||||
{
|
{
|
||||||
var ret = new List<string>();
|
var ret = new List<string>();
|
||||||
|
|
|
||||||
2
TShockAPI/DB/TileManager.cs
Normal file → Executable file
2
TShockAPI/DB/TileManager.cs
Normal file → Executable file
|
|
@ -41,7 +41,7 @@ namespace TShockAPI.DB
|
||||||
db.GetSqlType() == SqlType.Sqlite
|
db.GetSqlType() == SqlType.Sqlite
|
||||||
? (IQueryBuilder)new SqliteQueryCreator()
|
? (IQueryBuilder)new SqliteQueryCreator()
|
||||||
: new MysqlQueryCreator());
|
: new MysqlQueryCreator());
|
||||||
creator.EnsureExists(table);
|
creator.EnsureTableStructure(table);
|
||||||
UpdateBans();
|
UpdateBans();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ namespace TShockAPI.DB
|
||||||
db.GetSqlType() == SqlType.Sqlite
|
db.GetSqlType() == SqlType.Sqlite
|
||||||
? (IQueryBuilder) new SqliteQueryCreator()
|
? (IQueryBuilder) new SqliteQueryCreator()
|
||||||
: new MysqlQueryCreator());
|
: new MysqlQueryCreator());
|
||||||
creator.EnsureExists(table);
|
creator.EnsureTableStructure(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
2
TShockAPI/DB/WarpsManager.cs
Normal file → Executable file
2
TShockAPI/DB/WarpsManager.cs
Normal file → Executable file
|
|
@ -51,7 +51,7 @@ namespace TShockAPI.DB
|
||||||
db.GetSqlType() == SqlType.Sqlite
|
db.GetSqlType() == SqlType.Sqlite
|
||||||
? (IQueryBuilder) new SqliteQueryCreator()
|
? (IQueryBuilder) new SqliteQueryCreator()
|
||||||
: new MysqlQueryCreator());
|
: new MysqlQueryCreator());
|
||||||
creator.EnsureExists(table);
|
creator.EnsureTableStructure(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue