Adds Delete Row.
This commit is contained in:
parent
a435966f07
commit
203f3aa570
2 changed files with 38 additions and 0 deletions
|
|
@ -16,6 +16,7 @@ namespace TShockAPI.DB
|
|||
string UpdateValue(string table, List<SqlValue> values, List<SqlValue> wheres);
|
||||
string InsertValues(string table, List<SqlValue> values);
|
||||
string ReadColumn(string table, List<SqlValue> wheres);
|
||||
string DeleteRow(string table, List<SqlValue> wheres);
|
||||
}
|
||||
|
||||
public class SqliteQueryCreator : IQueryBuilder
|
||||
|
|
@ -51,6 +52,22 @@ namespace TShockAPI.DB
|
|||
* Twitchy - Oh. I get it!
|
||||
*/
|
||||
}
|
||||
public string DeleteRow(string table, List<SqlValue> 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<SqlValue> values, List<SqlValue> 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<SqlValue> 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<SqlValue> values, List<SqlValue> wheres)
|
||||
{
|
||||
var sbvalues = new StringBuilder();
|
||||
|
|
|
|||
|
|
@ -76,5 +76,10 @@ namespace TShockAPI.DB
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void DeleteRow(string table, List<SqlValue> wheres)
|
||||
{
|
||||
database.Query(creator.DeleteRow(table, wheres));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue