Compare commits

..

2 Commits

5 changed files with 44 additions and 14 deletions

View File

@ -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"]);
} }
} }
} }

View File

@ -21,6 +21,8 @@ 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)
{
try
{ {
await database.Execute(sql, (c) => await database.Execute(sql, (c) =>
{ {
@ -30,13 +32,41 @@ namespace HermesSocketServer.Store
foreach (var column in columns) foreach (var column in columns)
{ {
var propValue = columnPropertyRelations[column]!.GetValue(value); var propValue = columnPropertyRelations[column]!.GetValue(value);
var propType = columnPropertyRelations[column]!.PropertyType;
c.Parameters.AddWithValue(column.ToLower() + valueCounter, propValue ?? DBNull.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)
{ {

View File

@ -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"]);
} }
} }
} }

View File

@ -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"]);
} }
} }
} }

View File

@ -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"]);
} }
} }
} }