Compare commits
2 Commits
61151bef0c
...
4979553c74
Author | SHA1 | Date | |
---|---|---|---|
4979553c74 | |||
5618b28c49 |
@ -101,7 +101,7 @@ namespace HermesSocketServer.Store
|
|||||||
sql = _generator.GeneratePreparedDeleteSql("TtsChatVoice", count, ["userId", "chatterId"]);
|
sql = _generator.GeneratePreparedDeleteSql("TtsChatVoice", count, ["userId", "chatterId"]);
|
||||||
|
|
||||||
_logger.Debug($"User - Deleting {count} rows from database: {sql}");
|
_logger.Debug($"User - Deleting {count} rows from database: {sql}");
|
||||||
await _generator.DoPreparedStatement(_database, sql, list, ["id"]);
|
await _generator.DoPreparedStatementRaw(_database, sql, list, ["id"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,20 +22,50 @@ namespace HermesSocketServer.Store
|
|||||||
|
|
||||||
public async Task DoPreparedStatement<V>(Database database, string sql, IEnumerable<V> values, string[] columns)
|
public async Task DoPreparedStatement<V>(Database database, string sql, IEnumerable<V> values, string[] columns)
|
||||||
{
|
{
|
||||||
await database.Execute(sql, (c) =>
|
try
|
||||||
{
|
{
|
||||||
var valueCounter = 0;
|
await database.Execute(sql, (c) =>
|
||||||
foreach (var value in values)
|
|
||||||
{
|
{
|
||||||
foreach (var column in columns)
|
var valueCounter = 0;
|
||||||
|
foreach (var value in values)
|
||||||
{
|
{
|
||||||
var propValue = columnPropertyRelations[column]!.GetValue(value);
|
foreach (var column in columns)
|
||||||
var propType = columnPropertyRelations[column]!.PropertyType;
|
{
|
||||||
c.Parameters.AddWithValue(column.ToLower() + valueCounter, propValue ?? DBNull.Value);
|
var propValue = columnPropertyRelations[column]!.GetValue(value);
|
||||||
|
c.Parameters.AddWithValue(column.ToLower() + valueCounter, propValue ?? DBNull.Value);
|
||||||
|
}
|
||||||
|
valueCounter++;
|
||||||
}
|
}
|
||||||
valueCounter++;
|
});
|
||||||
}
|
}
|
||||||
});
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.Error(ex, "Failed to execute a prepared statement: " + sql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DoPreparedStatementRaw<V>(Database database, string sql, IEnumerable<V> values, string[] columns)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await database.Execute(sql, (c) =>
|
||||||
|
{
|
||||||
|
var valueCounter = 0;
|
||||||
|
foreach (var value in values)
|
||||||
|
{
|
||||||
|
foreach (var column in columns)
|
||||||
|
{
|
||||||
|
object? propValue = value;
|
||||||
|
c.Parameters.AddWithValue(column.ToLower() + valueCounter, propValue ?? DBNull.Value);
|
||||||
|
}
|
||||||
|
valueCounter++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.Error(ex, "Failed to execute a prepared statement: " + sql);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GenerateInsertSql(string table, IEnumerable<T> values, IEnumerable<string> columns)
|
public string GenerateInsertSql(string table, IEnumerable<T> values, IEnumerable<string> columns)
|
||||||
|
@ -107,7 +107,7 @@ namespace HermesSocketServer.Store
|
|||||||
sql = _generator.GeneratePreparedDeleteSql("GroupPermissionPolicy", count, ["id"]);
|
sql = _generator.GeneratePreparedDeleteSql("GroupPermissionPolicy", count, ["id"]);
|
||||||
|
|
||||||
_logger.Debug($"GroupPermissionPolicy - Deleting {count} rows from database: {sql}");
|
_logger.Debug($"GroupPermissionPolicy - Deleting {count} rows from database: {sql}");
|
||||||
await _generator.DoPreparedStatement(_database, sql, list, ["id"]);
|
await _generator.DoPreparedStatementRaw(_database, sql, list.Select(id => new Guid(id)), ["id"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ namespace HermesSocketServer.Store
|
|||||||
sql = _generator.GeneratePreparedDeleteSql("User", count, ["id"]);
|
sql = _generator.GeneratePreparedDeleteSql("User", count, ["id"]);
|
||||||
|
|
||||||
_logger.Debug($"User - Deleting {count} rows from database: {sql}");
|
_logger.Debug($"User - Deleting {count} rows from database: {sql}");
|
||||||
await _generator.DoPreparedStatement(_database, sql, list, ["id"]);
|
await _generator.DoPreparedStatementRaw(_database, sql, list, ["id"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ namespace HermesSocketServer.Store
|
|||||||
sql = _generator.GeneratePreparedDeleteSql("TtsVoice", count, ["id"]);
|
sql = _generator.GeneratePreparedDeleteSql("TtsVoice", count, ["id"]);
|
||||||
|
|
||||||
_logger.Debug($"User - Deleting {count} rows from database: {sql}");
|
_logger.Debug($"User - Deleting {count} rows from database: {sql}");
|
||||||
await _generator.DoPreparedStatement(_database, sql, list, ["id"]);
|
await _generator.DoPreparedStatementRaw(_database, sql, list, ["id"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user