Skip to content

Commit

Permalink
Simplify, add to Interface, add docs for boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
jas88 committed Oct 16, 2024
1 parent 69a749a commit a82b535
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 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
7 changes: 5 additions & 2 deletions FAnsiSql/Discovery/QuerySyntaxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ public abstract partial class QuerySyntaxHelper(
/// <inheritdoc/>
public virtual char[] IllegalNameChars { get; } = ['.', '(', ')'];

public abstract string False { get; }
public abstract string True { 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ public sealed class MicrosoftQuerySyntaxHelper : QuerySyntaxHelper

public override string CloseQualifier => "]";

public override string False => "0";

public override string True => "1";

public override TopXResponse HowDoWeAchieveTopX(int x) => new($"TOP {x}", QueryComponent.SELECT);

public override string GetParameterDeclaration(string proposedNewParameterName, string sqlType) => $"DECLARE {proposedNewParameterName} AS {sqlType};";
Expand Down
4 changes: 0 additions & 4 deletions FAnsiSql/Implementations/MySql/MySqlQuerySyntaxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ public sealed class MySqlQuerySyntaxHelper : QuerySyntaxHelper

public override string CloseQualifier => "`";

public override string False => "0";

public override string True => "1";

private MySqlQuerySyntaxHelper() : base(MySqlTypeTranslater.Instance, MySqlAggregateHelper.Instance,MySqlUpdateHelper.Instance,DatabaseType.MySql)//no specific type translation required
{
}
Expand Down
4 changes: 0 additions & 4 deletions FAnsiSql/Implementations/Oracle/OracleQuerySyntaxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ private OracleQuerySyntaxHelper() : base(OracleTypeTranslater.Instance, OracleAg

public override char ParameterSymbol => ':';

public override string False => "0";

public override string True => "1";

[return: NotNullIfNotNull(nameof(s))]
public override string? GetRuntimeName(string? s)
{
Expand Down
6 changes: 4 additions & 2 deletions FAnsiSql/Implementations/PostgreSql/PostgreSqlSyntaxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ private PostgreSqlSyntaxHelper() : base(PostgreSqlTypeTranslater.Instance, Postg

public override string CloseQualifier => "\"";

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

public override string True => "TRUE";
///<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;

Expand Down

0 comments on commit a82b535

Please sign in to comment.