Compare commits

..

No commits in common. "4979553c74dbb0bbe8fa6e89340e7ad14f007823" and "61151bef0ce03c47e183e6211cdfc3c03e78107f" have entirely different histories.

5 changed files with 14 additions and 44 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.DoPreparedStatementRaw(_database, sql, list, ["id"]); await _generator.DoPreparedStatement(_database, sql, list, ["id"]);
} }
} }
} }

View File

@ -21,8 +21,6 @@ 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) =>
{ {
@ -32,41 +30,13 @@ 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.DoPreparedStatementRaw(_database, sql, list.Select(id => new Guid(id)), ["id"]); await _generator.DoPreparedStatement(_database, sql, list, ["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.DoPreparedStatementRaw(_database, sql, list, ["id"]); await _generator.DoPreparedStatement(_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.DoPreparedStatementRaw(_database, sql, list, ["id"]); await _generator.DoPreparedStatement(_database, sql, list, ["id"]);
} }
} }
} }