Skip to content

Commit

Permalink
Merge branch 'main' into feature/fixwarnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jas88 authored Oct 16, 2024
2 parents 3e92df0 + 94de801 commit 41e0b76
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
9 changes: 9 additions & 0 deletions FAnsiSql/Discovery/QuerySyntax/IQuerySyntaxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ public interface IQuerySyntaxHelper
/// </summary>
int MaximumColumnLength { get; }

/// <summary>
/// Boolean false encoded appropriately for the DBMS (either 0 or FALSE depending)
/// </summary>
public string False { get; }

/// <summary>
/// Boolean true encoded appropriately for the DBMS (either 1 or TRUE depending)
/// </summary>
public string True { get; }

bool SplitLineIntoSelectSQLAndAlias(string lineToSplit, out string selectSQL, out string? alias);

Expand Down
6 changes: 6 additions & 0 deletions FAnsiSql/Discovery/QuerySyntaxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public abstract partial class QuerySyntaxHelper(
/// <inheritdoc/>
public virtual char[] IllegalNameChars { get; } = ['.', '(', ')'];

///<inheritdoc/>
public virtual string False => "0"; // 0 works as false for everything except Postgres

///<inheritdoc/>
public virtual string True => "1"; // 1 works as true for everything except Postgres

/// <summary>
/// Regex for identifying parameters in blocks of SQL (starts with @ or : (Oracle)
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion FAnsiSql/FAnsi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="MySqlConnector" Version="2.3.7" />
<PackageReference Include="Npgsql" Version="8.0.4" />
<PackageReference Include="Npgsql" Version="8.0.5" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="23.6.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions FAnsiSql/Implementations/PostgreSql/PostgreSqlSyntaxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ private PostgreSqlSyntaxHelper() : base(PostgreSqlTypeTranslater.Instance, Postg

public override string CloseQualifier => "\"";

///<inheritdoc/>
public override string False => "FALSE"; // 'FALSE' is the string representation of the boolean false in PostgreSql, unlike 0 for the others

///<inheritdoc/>
public override string True => "TRUE"; // 'TRUE' is the string representation of the boolean true in PostgreSql, unlike 1 for the others

public override bool SupportsEmbeddedParameters() => false;

protected override object FormatDateTimeForDbParameter(DateTime dateTime) =>
Expand Down
2 changes: 1 addition & 1 deletion Tests/FAnsiTests/FAnsiTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NunitXml.TestLogger" Version="4.0.254" />
<PackageReference Include="NunitXml.TestLogger" Version="4.1.0" />
</ItemGroup>
<ItemGroup>
<Content Include="TestDatabases.xml">
Expand Down
12 changes: 12 additions & 0 deletions Tests/FAnsiTests/Query/QuerySyntaxHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ public void Test_GetAlias(DatabaseType t)
});
}

[TestCaseSource(typeof(All), nameof(All.DatabaseTypes))]
public void Test_BooleanWrapper(DatabaseType dbType)
{
Assert.Multiple(() =>
{
var syntaxHelper = ImplementationManager.GetImplementation(dbType).GetQuerySyntaxHelper();
Assert.That(syntaxHelper.True, Is.EqualTo(dbType == DatabaseType.PostgreSql ? "TRUE" : "1"));
Assert.That(syntaxHelper.False, Is.EqualTo(dbType == DatabaseType.PostgreSql ? "FALSE" : "0"));
});
}

[TestCaseSource(typeof(All),nameof(All.DatabaseTypes))]
public void Test_NameValidation(DatabaseType dbType)
{
Expand Down

0 comments on commit 41e0b76

Please sign in to comment.