Skip to content

Commit

Permalink
Audit.NET.PostgreSql: Fixing postgres double quote issue. (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
thepirat000 committed Sep 15, 2023
1 parent 47437c0 commit 0485eb2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>21.0.3</Version>
<Version>21.0.4</Version>
<PackageReleaseNotes></PackageReleaseNotes>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Audit.NET.PostgreSql/Providers/PostgreSqlDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public IEnumerable<AuditEvent> EnumerateEvents(string whereExpression)
public IEnumerable<T> EnumerateEvents<T>(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<T>(sql);
}

Expand All @@ -266,7 +266,7 @@ public IEnumerable<T> EnumerateEvents<T>(string whereExpression) where T : Audit
/// </remarks>
public IEnumerable<T> EnumerateEvents<T>(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}";
Expand Down
32 changes: 32 additions & 0 deletions test/Audit.IntegrationTest/PostgreSqlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuditEvent>(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 */
Expand Down

0 comments on commit 0485eb2

Please sign in to comment.