Added exception handling option to AddBan & Remove Ban
Fixed formatting of EnsureExists(table) block
This commit is contained in:
parent
2f3bfca082
commit
2f7cb9f44e
1 changed files with 16 additions and 11 deletions
|
|
@ -40,15 +40,15 @@ namespace TShockAPI.DB
|
||||||
db.GetSqlType() == SqlType.Sqlite
|
db.GetSqlType() == SqlType.Sqlite
|
||||||
? (IQueryBuilder) new SqliteQueryCreator()
|
? (IQueryBuilder) new SqliteQueryCreator()
|
||||||
: new MysqlQueryCreator());
|
: new MysqlQueryCreator());
|
||||||
try{
|
try
|
||||||
|
{
|
||||||
creator.EnsureExists(table);
|
creator.EnsureExists(table);
|
||||||
}
|
}
|
||||||
catch (DllNotFoundException ex)
|
catch (DllNotFoundException)
|
||||||
{
|
{
|
||||||
System.Console.WriteLine("Possible problem with your database - is Sqlite3.dll present?");
|
System.Console.WriteLine("Possible problem with your database - is Sqlite3.dll present?");
|
||||||
throw new Exception("Could not find a database library (probably Sqlite3.dll)");
|
throw new Exception("Could not find a database library (probably Sqlite3.dll)");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ban GetBanByIp(string ip)
|
public Ban GetBanByIp(string ip)
|
||||||
|
|
@ -110,7 +110,7 @@ throw new Exception("Could not find a database library (probably Sqlite3.dll)");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AddBan(string ip, string name = "", string reason = "")
|
public bool AddBan(string ip, string name = "", string reason = "", bool exceptions = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -118,12 +118,15 @@ throw new Exception("Could not find a database library (probably Sqlite3.dll)");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
if (exceptions)
|
||||||
|
throw ex;
|
||||||
Log.Error(ex.ToString());
|
Log.Error(ex.ToString());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool RemoveBan(string match, bool byName = false, bool casesensitive = true)
|
|
||||||
|
public bool RemoveBan(string match, bool byName = false, bool casesensitive = true, bool exceptions = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -135,6 +138,8 @@ throw new Exception("Could not find a database library (probably Sqlite3.dll)");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
if (exceptions)
|
||||||
|
throw ex;
|
||||||
Log.Error(ex.ToString());
|
Log.Error(ex.ToString());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue