From 5618b28c49518c8e6b814062947837ff3d88ecb6 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 31 Oct 2024 15:42:43 +0000 Subject: [PATCH] Fixed delete prepared statements from stores --- Store/ChatterStore.cs | 2 +- Store/GroupSaveSqlGenerator.cs | 18 +++++++++++++++++- Store/PolicyStore.cs | 2 +- Store/UserStore.cs | 2 +- Store/VoiceStore.cs | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Store/ChatterStore.cs b/Store/ChatterStore.cs index b65169f..ba890a6 100644 --- a/Store/ChatterStore.cs +++ b/Store/ChatterStore.cs @@ -101,7 +101,7 @@ namespace HermesSocketServer.Store sql = _generator.GeneratePreparedDeleteSql("TtsChatVoice", count, ["userId", "chatterId"]); _logger.Debug($"User - Deleting {count} rows from database: {sql}"); - await _generator.DoPreparedStatement(_database, sql, list, ["id"]); + await _generator.DoPreparedStatementRaw(_database, sql, list, ["id"]); } } } diff --git a/Store/GroupSaveSqlGenerator.cs b/Store/GroupSaveSqlGenerator.cs index a4064c6..b913dc4 100644 --- a/Store/GroupSaveSqlGenerator.cs +++ b/Store/GroupSaveSqlGenerator.cs @@ -30,7 +30,23 @@ namespace HermesSocketServer.Store foreach (var column in columns) { 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(Database database, string sql, IEnumerable 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); } valueCounter++; diff --git a/Store/PolicyStore.cs b/Store/PolicyStore.cs index 59e6254..d2b8b63 100644 --- a/Store/PolicyStore.cs +++ b/Store/PolicyStore.cs @@ -107,7 +107,7 @@ namespace HermesSocketServer.Store sql = _generator.GeneratePreparedDeleteSql("GroupPermissionPolicy", count, ["id"]); _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"]); } } } diff --git a/Store/UserStore.cs b/Store/UserStore.cs index b90d855..7d63128 100644 --- a/Store/UserStore.cs +++ b/Store/UserStore.cs @@ -102,7 +102,7 @@ namespace HermesSocketServer.Store sql = _generator.GeneratePreparedDeleteSql("User", count, ["id"]); _logger.Debug($"User - Deleting {count} rows from database: {sql}"); - await _generator.DoPreparedStatement(_database, sql, list, ["id"]); + await _generator.DoPreparedStatementRaw(_database, sql, list, ["id"]); } } } diff --git a/Store/VoiceStore.cs b/Store/VoiceStore.cs index e6b4d35..635f52d 100644 --- a/Store/VoiceStore.cs +++ b/Store/VoiceStore.cs @@ -104,7 +104,7 @@ namespace HermesSocketServer.Store sql = _generator.GeneratePreparedDeleteSql("TtsVoice", count, ["id"]); _logger.Debug($"User - Deleting {count} rows from database: {sql}"); - await _generator.DoPreparedStatement(_database, sql, list, ["id"]); + await _generator.DoPreparedStatementRaw(_database, sql, list, ["id"]); } } }