Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ namespace FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests.Query;

public class NorthwindAggregateOperatorsQueryFbTest : NorthwindAggregateOperatorsQueryRelationalTestBase<NorthwindQueryFbFixture<NoopModelCustomizer>>
{
private readonly NorthwindQueryFbFixture<NoopModelCustomizer> _fixture;

public NorthwindAggregateOperatorsQueryFbTest(NorthwindQueryFbFixture<NoopModelCustomizer> fixture)
: base(fixture)
{ }
{
_fixture = fixture;
}

[NotSupportedOnFirebirdTheory]
[MemberData(nameof(IsAsyncData))]
Expand Down Expand Up @@ -96,4 +100,11 @@ public override Task Average_over_nested_subquery(bool async)
{
return base.Average_over_nested_subquery(async);
}

[Theory(Skip = "Different math on Firebird.")]
[MemberData(nameof(IsAsyncData))]
public override Task Contains_with_local_collection_sql_injection(bool async)
{
return base.Contains_with_local_collection_sql_injection(async);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ namespace FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests.Query;

public class NorthwindMiscellaneousQueryFbTest : NorthwindMiscellaneousQueryRelationalTestBase<NorthwindQueryFbFixture<NoopModelCustomizer>>
{
private readonly NorthwindQueryFbFixture<NoopModelCustomizer> _fixture;

public NorthwindMiscellaneousQueryFbTest(NorthwindQueryFbFixture<NoopModelCustomizer> fixture)
: base(fixture)
{ }
{
_fixture = fixture;
}

[Theory]
[MemberData(nameof(IsAsyncData))]
Expand Down Expand Up @@ -159,4 +163,11 @@ public override Task Where_nanosecond_and_microsecond_component(bool async)
{
return base.Where_nanosecond_and_microsecond_component(async);
}

[NotSupportedByProviderTheory]
[MemberData(nameof(IsAsyncData))]
public override Task Contains_over_concatenated_columns_both_fixed_length(bool async)
{
return base.Contains_over_concatenated_columns_both_fixed_length(async);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ protected override Expression VisitSqlParameter(SqlParameterExpression sqlParame
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 ?? 0;
Sql.Append(((IFbSqlGenerationHelper)Dependencies.SqlGenerationHelper).StringParameterQueryType(isUnicode, storeTypeNameBase, size));
}
else
{
Expand All @@ -192,8 +194,11 @@ protected override Expression VisitSqlConstant(SqlConstantExpression sqlConstant
if (shouldExplicitStringLiteralTypes)
{
var isUnicode = FbTypeMappingSource.IsUnicode(sqlConstantExpression.TypeMapping);
var storeTypeNameBase = sqlConstantExpression.TypeMapping.StoreTypeNameBase;
var size = sqlConstantExpression.TypeMapping.Size ?? 0;

Sql.Append(" AS ");
Sql.Append(((IFbSqlGenerationHelper)Dependencies.SqlGenerationHelper).StringLiteralQueryType(sqlConstantExpression.Value as string, isUnicode));
Sql.Append(((IFbSqlGenerationHelper)Dependencies.SqlGenerationHelper).StringLiteralQueryType(sqlConstantExpression.Value as string, isUnicode, storeTypeNameBase, size));
Sql.Append(")");
}
return sqlConstantExpression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,38 @@ public FbSqlGenerationHelper(RelationalSqlGenerationHelperDependencies dependenc
: base(dependencies)
{ }

public virtual string StringLiteralQueryType(string s, bool isUnicode = true)
public virtual string StringLiteralQueryType(string s, bool isUnicode = true, string storeTypeNameBase = "", int size = 0)
{
var length = MinimumStringQueryTypeLength(s);
var maxSize = MinimumStringQueryTypeLength(s);
string typeName;
if (storeTypeNameBase.Equals("BLOB SUB_TYPE TEXT", StringComparison.OrdinalIgnoreCase))
{
typeName = "VARCHAR";
}
else
{
typeName = IsEmpty(storeTypeNameBase) ? "VARCHAR" : storeTypeNameBase;
}

var charset = isUnicode ? " CHARACTER SET UTF8" : string.Empty;
return $"VARCHAR({length}){charset}";
return $"{typeName}({maxSize}){charset}";
}

public virtual string StringParameterQueryType(bool isUnicode)
public virtual string StringParameterQueryType(bool isUnicode, string storeTypeNameBase = "", int size = 0)
{
var size = isUnicode ? FbTypeMappingSource.UnicodeVarcharMaxSize : FbTypeMappingSource.VarcharMaxSize;
return $"VARCHAR({size})";
int maxSize;
string typeName;
if (storeTypeNameBase.Equals("BLOB SUB_TYPE TEXT", StringComparison.OrdinalIgnoreCase))
{
maxSize = (isUnicode ? FbTypeMappingSource.UnicodeVarcharMaxSize : FbTypeMappingSource.VarcharMaxSize);
typeName = "VARCHAR";
}
else
{
maxSize = size > 0 ? size : (isUnicode ? FbTypeMappingSource.UnicodeVarcharMaxSize : FbTypeMappingSource.VarcharMaxSize);
typeName = IsEmpty(storeTypeNameBase) ? "VARCHAR" : storeTypeNameBase;
}
return $"{typeName}({maxSize})";
}

public virtual void GenerateBlockParameterName(StringBuilder builder, string name)
Expand All @@ -47,17 +68,16 @@ public virtual void GenerateBlockParameterName(StringBuilder builder, string nam

public virtual string AlternativeStatementTerminator => "~";

static int MinimumStringQueryTypeLength(string s)
private int MinimumStringQueryTypeLength(string s)
{
var length = s?.Length ?? 0;
if (length == 0)
length = 1;
return length;
}

static void EnsureStringLiteralQueryTypeLength(int length)
private bool IsEmpty(string storeTypeNameBase)
{
if (length > FbTypeMappingSource.UnicodeVarcharMaxSize)
throw new ArgumentOutOfRangeException(nameof(length));
return (storeTypeNameBase == null || string.IsNullOrEmpty(storeTypeNameBase) || string.IsNullOrWhiteSpace(storeTypeNameBase));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace FirebirdSql.EntityFrameworkCore.Firebird.Storage.Internal;

public interface IFbSqlGenerationHelper : ISqlGenerationHelper
{
string StringLiteralQueryType(string s, bool isUnicode);
string StringParameterQueryType(bool isUnicode);
string StringLiteralQueryType(string s, bool isUnicode, string storeTypeNameBase = "", int size = 0);
string StringParameterQueryType(bool isUnicode, string storeTypeNameBase = "", int size = 0);
void GenerateBlockParameterName(StringBuilder builder, string name);
string AlternativeStatementTerminator { get; }
}