diff --git a/Store/GroupSaveSqlGenerator.cs b/Store/GroupSaveSqlGenerator.cs index b913dc4..d9df6fe 100644 --- a/Store/GroupSaveSqlGenerator.cs +++ b/Store/GroupSaveSqlGenerator.cs @@ -22,36 +22,50 @@ namespace HermesSocketServer.Store public async Task DoPreparedStatement(Database database, string sql, IEnumerable values, string[] columns) { - await database.Execute(sql, (c) => + try { - var valueCounter = 0; - foreach (var value in values) + await database.Execute(sql, (c) => { - foreach (var column in columns) + var valueCounter = 0; + foreach (var value in values) { - var propValue = columnPropertyRelations[column]!.GetValue(value); - c.Parameters.AddWithValue(column.ToLower() + valueCounter, propValue ?? DBNull.Value); + foreach (var column in columns) + { + 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(Database database, string sql, IEnumerable values, string[] columns) { - await database.Execute(sql, (c) => + try { - var valueCounter = 0; - foreach (var value in values) + await database.Execute(sql, (c) => { - foreach (var column in columns) + var valueCounter = 0; + foreach (var value in values) { - object? propValue = value; - c.Parameters.AddWithValue(column.ToLower() + valueCounter, propValue ?? DBNull.Value); + foreach (var column in columns) + { + object? propValue = 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 string GenerateInsertSql(string table, IEnumerable values, IEnumerable columns)