diff --git a/TShockAPI/DB/IQueryBuilder.cs b/TShockAPI/DB/IQueryBuilder.cs index e2b96775..e88d7c9c 100644 --- a/TShockAPI/DB/IQueryBuilder.cs +++ b/TShockAPI/DB/IQueryBuilder.cs @@ -16,6 +16,7 @@ namespace TShockAPI.DB string UpdateValue(string table, List values, List wheres); string InsertValues(string table, List values); string ReadColumn(string table, List wheres); + string DeleteRow(string table, List wheres); } public class SqliteQueryCreator : IQueryBuilder @@ -51,6 +52,22 @@ namespace TShockAPI.DB * Twitchy - Oh. I get it! */ } + public string DeleteRow(string table, List wheres) + { + var sbwheres = new StringBuilder(); + int count = 0; + foreach (SqlValue where in wheres) + { + sbwheres.Append(where.Name + "=" + where.Value.ToString()); + if (count != wheres.Count - 1) + sbwheres.Append(" AND "); + count++; + } + if (wheres.Count > 0) + return "DELETE FROM '{0}' WHERE {1} ".SFormat(table, sbwheres.ToString()); + else + return "DELETE FROM '{0}'".SFormat(table, sbwheres.ToString()); + } public string UpdateValue(string table, List values, List wheres) { var sbvalues = new StringBuilder(); @@ -164,6 +181,22 @@ namespace TShockAPI.DB var drop = "DROP TABLE {0}_{1}".SFormat(rstr, from.Name); return "{0}; {1}; {2}; {3};".SFormat(alter, create, insert, drop); } + public string DeleteRow(string table, List wheres) + { + var sbwheres = new StringBuilder(); + int count = 0; + foreach (SqlValue where in wheres) + { + sbwheres.Append(where.Name + "=" + where.Value.ToString()); + if (count != wheres.Count - 1) + sbwheres.Append(" AND "); + count++; + } + if (wheres.Count > 0) + return "DELETE FROM {0} WHERE {1} ".SFormat(table, sbwheres.ToString()); + else + return "DELETE FROM {0}".SFormat(table, sbwheres.ToString()); + } public string UpdateValue(string table, List values, List wheres) { var sbvalues = new StringBuilder(); diff --git a/TShockAPI/DB/SqlTable.cs b/TShockAPI/DB/SqlTable.cs index 3ccca4c4..21d289e1 100644 --- a/TShockAPI/DB/SqlTable.cs +++ b/TShockAPI/DB/SqlTable.cs @@ -76,5 +76,10 @@ namespace TShockAPI.DB return ret; } + + public void DeleteRow(string table, List wheres) + { + database.Query(creator.DeleteRow(table, wheres)); + } } }