From fc59db7626df1dcbab6d7e14a95494dfa9124083 Mon Sep 17 00:00:00 2001 From: Gilson Joanelo Date: Tue, 24 Sep 2024 09:58:51 -0300 Subject: [PATCH 1/4] 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/4] 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/4] 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}"; } From 776a927e57708da5c2176f327bb680b7418eeb5a Mon Sep 17 00:00:00 2001 From: Gilson Joanelo Date: Mon, 26 May 2025 15:59:24 -0300 Subject: [PATCH 4/4] =?UTF-8?q?Corre=C3=A7=C3=A3o=20do=20erro=20Implementa?= =?UTF-8?q?tion=20limit=20exceeded?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Correção da falha SQL error code = -204 Implementation limit exceeded block size exceeds implementation restriction --- .../Query/Internal/FbQuerySqlGenerator.cs | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/FirebirdSql.EntityFrameworkCore.Firebird/Query/Internal/FbQuerySqlGenerator.cs b/src/FirebirdSql.EntityFrameworkCore.Firebird/Query/Internal/FbQuerySqlGenerator.cs index 17fb2ff6..9cd84cc2 100644 --- a/src/FirebirdSql.EntityFrameworkCore.Firebird/Query/Internal/FbQuerySqlGenerator.cs +++ b/src/FirebirdSql.EntityFrameworkCore.Firebird/Query/Internal/FbQuerySqlGenerator.cs @@ -169,8 +169,18 @@ protected override Expression VisitSqlParameter(SqlParameterExpression sqlParame Sql.Append(" AS "); if (sqlParameterExpression.Type == typeof(string)) { - var isUnicode = FbTypeMappingSource.IsUnicode(sqlParameterExpression.TypeMapping); - Sql.Append(((IFbSqlGenerationHelper)Dependencies.SqlGenerationHelper).StringParameterQueryType(isUnicode)); + var storeTypeNameBase = sqlParameterExpression.TypeMapping.StoreTypeNameBase; + var size = sqlParameterExpression.TypeMapping.Size; + + if (storeTypeNameBase != null && size != null) + { + Sql.Append($"{storeTypeNameBase}({size})"); + } + else + { + var isUnicode = FbTypeMappingSource.IsUnicode(sqlParameterExpression.TypeMapping); + Sql.Append(((IFbSqlGenerationHelper)Dependencies.SqlGenerationHelper).StringParameterQueryType(isUnicode)); + } } else { @@ -191,9 +201,19 @@ 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, isUnicode)); + var storeTypeNameBase = sqlConstantExpression.TypeMapping.StoreTypeNameBase; + var size = sqlConstantExpression.TypeMapping.Size; + + if (storeTypeNameBase != null && size != null) + { + Sql.Append($"{storeTypeNameBase}({size})"); + } + else + { + var isUnicode = FbTypeMappingSource.IsUnicode(sqlConstantExpression.TypeMapping); + Sql.Append(" AS "); + Sql.Append(((IFbSqlGenerationHelper)Dependencies.SqlGenerationHelper).StringLiteralQueryType(sqlConstantExpression.Value as string, isUnicode)); + } Sql.Append(")"); } return sqlConstantExpression;