diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bdbd610..e35c8a06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ All notable changes to Audit.NET and its extensions will be documented in this f The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). +## [21.0.4] - 2023-09-15 +- Audit.NET.PostgreSql: Fixing postgres double quote issue. (#623) + ## [21.0.3] - 2023-07-09 - Audit.EntityFramework / Audit.EntityFramework.Core: Adding `ReloadDatabaseValues` configuration to AuditDbContextAttribute. (#53, #607) - Audit.NET.MongoDB: Exposing API to provide the entire MongoDB.Driver.MongoClientSettings instead of the connection string. (#614) diff --git a/Directory.Build.props b/Directory.Build.props index c09b8958..579a2df7 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 21.0.3 + 21.0.4 false diff --git a/src/Audit.NET.PostgreSql/Providers/PostgreSqlDataProvider.cs b/src/Audit.NET.PostgreSql/Providers/PostgreSqlDataProvider.cs index 75d2621d..6bb0beda 100644 --- a/src/Audit.NET.PostgreSql/Providers/PostgreSqlDataProvider.cs +++ b/src/Audit.NET.PostgreSql/Providers/PostgreSqlDataProvider.cs @@ -248,7 +248,7 @@ public IEnumerable EnumerateEvents(string whereExpression) public IEnumerable EnumerateEvents(string whereExpression) where T : AuditEvent { var where = string.IsNullOrWhiteSpace(whereExpression) ? "" : $"WHERE {whereExpression}"; - var sql = $@"SELECT ""{GetDataColumnName(null)}"" FROM {GetFullTableName(null)}"" {where}"; + var sql = $@"SELECT ""{GetDataColumnName(null)}"" FROM {GetFullTableName(null)} {where}"; return EnumerateEventsByFullSql(sql); } @@ -266,7 +266,7 @@ public IEnumerable EnumerateEvents(string whereExpression) where T : Audit /// public IEnumerable EnumerateEvents(string whereExpression, string orderByExpression, string limitExpression) where T : AuditEvent { - var selectExpression = $@"""{GetDataColumnName(null)}"" FROM {GetFullTableName(null)}"""; + var selectExpression = $@"""{GetDataColumnName(null)}"" FROM {GetFullTableName(null)}"; var where = string.IsNullOrWhiteSpace(whereExpression) ? "" : $" WHERE {whereExpression}"; var orderBy = string.IsNullOrWhiteSpace(orderByExpression) ? "" : $" ORDER BY {orderByExpression}"; var limit = string.IsNullOrWhiteSpace(limitExpression) ? "" : $" LIMIT {limitExpression}"; diff --git a/test/Audit.IntegrationTest/PostgreSqlTests.cs b/test/Audit.IntegrationTest/PostgreSqlTests.cs index 3ffea4ce..90ea4ef5 100644 --- a/test/Audit.IntegrationTest/PostgreSqlTests.cs +++ b/test/Audit.IntegrationTest/PostgreSqlTests.cs @@ -76,6 +76,38 @@ public void Test_PostgreDataProvider_Paging_With_Where() Assert.IsNotNull(realizedEvents); } + [Test] + public void Test_EnumerateEvents_WhereExpression() + { + var overrideEventType = Guid.NewGuid().ToString(); + var dp = GetConfiguredPostgreSqlDataProvider(overrideEventType); + + var scope = AuditScope.Create("test", null); + scope.Dispose(); + + var whereExpression = @"""" + GetLastUpdatedColumnNameColumnName() + @""" > '12/31/1900'"; + var events = dp?.EnumerateEvents(whereExpression); + var ev = events?.FirstOrDefault(); + + Assert.IsNotNull(ev); + } + + [Test] + public void Test_EnumerateEvents_WhereSortByExpression() + { + var overrideEventType = Guid.NewGuid().ToString(); + var dp = GetConfiguredPostgreSqlDataProvider(overrideEventType); + + var scope = AuditScope.Create("test", null); + scope.Dispose(); + + var whereExpression = @"""" + GetLastUpdatedColumnNameColumnName() + @""" > '12/31/1900'"; + var events = dp?.EnumerateEvents(whereExpression, GetLastUpdatedColumnNameColumnName(), "1"); + var ev = events?.FirstOrDefault(); + + Assert.IsNotNull(ev); + } + private static string GetLastUpdatedColumnNameColumnName() { /* this value is encapsulated so both RunLocalAuditConfiguration and Test_PostgreDataProvider_Paging_With_Where use the same value */