From fc59db7626df1dcbab6d7e14a95494dfa9124083 Mon Sep 17 00:00:00 2001 From: Gilson Joanelo Date: Tue, 24 Sep 2024 09:58:51 -0300 Subject: [PATCH 1/3] Add isUnicode parameter to StringLiteralQueryType function --- .../Query/Internal/FbQuerySqlGenerator.cs | 3 ++- .../Storage/Internal/FbSqlGenerationHelper.cs | 8 ++++++-- .../Storage/Internal/IFbSqlGenerationHelper.cs | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/FirebirdSql.EntityFrameworkCore.Firebird/Query/Internal/FbQuerySqlGenerator.cs b/src/FirebirdSql.EntityFrameworkCore.Firebird/Query/Internal/FbQuerySqlGenerator.cs index c8f203bf..64a79623 100644 --- a/src/FirebirdSql.EntityFrameworkCore.Firebird/Query/Internal/FbQuerySqlGenerator.cs +++ b/src/FirebirdSql.EntityFrameworkCore.Firebird/Query/Internal/FbQuerySqlGenerator.cs @@ -191,8 +191,9 @@ protected override Expression VisitSqlConstant(SqlConstantExpression sqlConstant base.VisitSqlConstant(sqlConstantExpression); if (shouldExplicitStringLiteralTypes) { + var isUnicode = FbTypeMappingSource.IsUnicode(sqlConstantExpression.TypeMapping); Sql.Append(" AS "); - Sql.Append(((IFbSqlGenerationHelper)Dependencies.SqlGenerationHelper).StringLiteralQueryType(sqlConstantExpression.Value as string)); + Sql.Append(((IFbSqlGenerationHelper)Dependencies.SqlGenerationHelper).StringLiteralQueryType(sqlConstantExpression.Value as string, isUnicode)); Sql.Append(")"); } return sqlConstantExpression; diff --git a/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/FbSqlGenerationHelper.cs b/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/FbSqlGenerationHelper.cs index 3aa22fc4..865f52a2 100644 --- a/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/FbSqlGenerationHelper.cs +++ b/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/FbSqlGenerationHelper.cs @@ -27,11 +27,15 @@ public FbSqlGenerationHelper(RelationalSqlGenerationHelperDependencies dependenc : base(dependencies) { } - public virtual string StringLiteralQueryType(string s) + public virtual string StringLiteralQueryType(string s, bool isUnicode = true) { var length = MinimumStringQueryTypeLength(s); EnsureStringLiteralQueryTypeLength(length); - return $"VARCHAR({length}) CHARACTER SET UTF8"; + if(isUnicode) + { + return $"VARCHAR({length}) CHARACTER SET UTF8"; + } + return $"VARCHAR({length})"; } public virtual string StringParameterQueryType(bool isUnicode) diff --git a/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/IFbSqlGenerationHelper.cs b/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/IFbSqlGenerationHelper.cs index 149cb2a9..56c4c1f5 100644 --- a/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/IFbSqlGenerationHelper.cs +++ b/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/IFbSqlGenerationHelper.cs @@ -22,7 +22,7 @@ namespace FirebirdSql.EntityFrameworkCore.Firebird.Storage.Internal; public interface IFbSqlGenerationHelper : ISqlGenerationHelper { - string StringLiteralQueryType(string s); + string StringLiteralQueryType(string s, bool isUnicode); string StringParameterQueryType(bool isUnicode); void GenerateBlockParameterName(StringBuilder builder, string name); string AlternativeStatementTerminator { get; } From b2c7eb9de569797a7c8cdfb6a53fcd2a07ac9c7e Mon Sep 17 00:00:00 2001 From: Gilson Joanelo Date: Wed, 25 Sep 2024 20:09:33 -0300 Subject: [PATCH 2/3] Update code to use ternary operator --- .../Storage/Internal/FbSqlGenerationHelper.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/FbSqlGenerationHelper.cs b/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/FbSqlGenerationHelper.cs index 865f52a2..8166671d 100644 --- a/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/FbSqlGenerationHelper.cs +++ b/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/FbSqlGenerationHelper.cs @@ -30,12 +30,8 @@ public FbSqlGenerationHelper(RelationalSqlGenerationHelperDependencies dependenc public virtual string StringLiteralQueryType(string s, bool isUnicode = true) { var length = MinimumStringQueryTypeLength(s); - EnsureStringLiteralQueryTypeLength(length); - if(isUnicode) - { - return $"VARCHAR({length}) CHARACTER SET UTF8"; - } - return $"VARCHAR({length})"; + var charset = isUnicode ? " CHARACTER SET UTF8" : ""; + return $"VARCHAR({length}){charset}"; } public virtual string StringParameterQueryType(bool isUnicode) From 4dd2e5a45aadd6d3dd0c3141e9c3bd08227a1d35 Mon Sep 17 00:00:00 2001 From: Gilson Joanelo Date: Thu, 26 Sep 2024 08:34:21 -0300 Subject: [PATCH 3/3] Change to string.empty --- .../Storage/Internal/FbSqlGenerationHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/FbSqlGenerationHelper.cs b/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/FbSqlGenerationHelper.cs index 8166671d..78bbff57 100644 --- a/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/FbSqlGenerationHelper.cs +++ b/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/FbSqlGenerationHelper.cs @@ -30,7 +30,7 @@ public FbSqlGenerationHelper(RelationalSqlGenerationHelperDependencies dependenc public virtual string StringLiteralQueryType(string s, bool isUnicode = true) { var length = MinimumStringQueryTypeLength(s); - var charset = isUnicode ? " CHARACTER SET UTF8" : ""; + var charset = isUnicode ? " CHARACTER SET UTF8" : string.Empty; return $"VARCHAR({length}){charset}"; }