Fixed delete prepared statements from stores

This commit is contained in:
Tom 2024-10-31 15:42:43 +00:00
parent 61151bef0c
commit 5618b28c49
5 changed files with 21 additions and 5 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

@ -30,7 +30,23 @@ 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);
}
valueCounter++;
}
});
}
public async Task DoPreparedStatementRaw<V>(Database database, string sql, IEnumerable<V> values, string[] columns)
{
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); c.Parameters.AddWithValue(column.ToLower() + valueCounter, propValue ?? DBNull.Value);
} }
valueCounter++; valueCounter++;

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