Skip to content

Commit 9c07e40

Browse files
committed
Byte array translations.
1 parent d58f119 commit 9c07e40

File tree

3 files changed

+17
-73
lines changed

3 files changed

+17
-73
lines changed

Provider/src/FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests/Query/GearsOfWarQueryFbTest.cs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
using FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests.Helpers;
2020
using Microsoft.EntityFrameworkCore.Query;
2121
using Xunit;
22-
using System.Linq;
23-
using Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel;
2422

2523
namespace FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests.Query
2624
{
@@ -30,27 +28,6 @@ public GearsOfWarQueryFbTest(GearsOfWarQueryFbFixture fixture)
3028
: base(fixture)
3129
{ }
3230

33-
[NotSupportedOnFirebirdTheory]
34-
[MemberData(nameof(IsAsyncData))]
35-
public override Task Byte_array_contains_parameter(bool async)
36-
{
37-
return base.Byte_array_contains_parameter(async);
38-
}
39-
40-
[NotSupportedOnFirebirdTheory]
41-
[MemberData(nameof(IsAsyncData))]
42-
public override Task Byte_array_contains_literal(bool async)
43-
{
44-
return base.Byte_array_contains_literal(async);
45-
}
46-
47-
[NotSupportedOnFirebirdTheory]
48-
[MemberData(nameof(IsAsyncData))]
49-
public override Task Contains_on_byte_array_property_using_byte_column(bool async)
50-
{
51-
return base.Contains_on_byte_array_property_using_byte_column(async);
52-
}
53-
5431
[NotSupportedOnFirebirdTheory]
5532
[MemberData(nameof(IsAsyncData))]
5633
public override Task DateTimeOffset_DateAdd_AddDays(bool isAsync)

Provider/src/FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests/Query/TPTGearsOfWarQueryFbTest.cs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,9 @@
1515

1616
//$Authors = Jiri Cincura (jiri@cincura.net)
1717

18-
using System;
19-
using System.Data.Common;
20-
using System.Linq;
2118
using System.Threading.Tasks;
22-
using FirebirdSql.Data.FirebirdClient;
2319
using FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests.Helpers;
2420
using Microsoft.EntityFrameworkCore.Query;
25-
using Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel;
26-
using Microsoft.EntityFrameworkCore.TestUtilities;
2721
using Xunit;
2822

2923
namespace FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests.Query
@@ -34,27 +28,6 @@ public TPTGearsOfWarQueryFbTest(TPTGearsOfWarQueryFbFixture fixture)
3428
: base(fixture)
3529
{ }
3630

37-
[NotSupportedOnFirebirdTheory]
38-
[MemberData(nameof(IsAsyncData))]
39-
public override Task Byte_array_contains_parameter(bool async)
40-
{
41-
return base.Byte_array_contains_parameter(async);
42-
}
43-
44-
[NotSupportedOnFirebirdTheory]
45-
[MemberData(nameof(IsAsyncData))]
46-
public override Task Byte_array_contains_literal(bool async)
47-
{
48-
return base.Byte_array_contains_literal(async);
49-
}
50-
51-
[NotSupportedOnFirebirdTheory]
52-
[MemberData(nameof(IsAsyncData))]
53-
public override Task Contains_on_byte_array_property_using_byte_column(bool async)
54-
{
55-
return base.Contains_on_byte_array_property_using_byte_column(async);
56-
}
57-
5831
[NotSupportedOnFirebirdTheory]
5932
[MemberData(nameof(IsAsyncData))]
6033
public override Task Correlated_collections_inner_subquery_predicate_references_outer_qsre(bool async)

Provider/src/FirebirdSql.EntityFrameworkCore.Firebird/Query/ExpressionTranslators/Internal/FbByteArrayMethodTranslator.cs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,24 @@ public FbByteArrayMethodTranslator(FbSqlExpressionFactory fbSqlExpressionFactory
3636

3737
public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments, IDiagnosticsLogger<DbLoggerCategory.Query> logger)
3838
{
39-
// POSITION works only with text blobs at the moment
39+
if (method.IsGenericMethod
40+
&& method.GetGenericMethodDefinition().Equals(EnumerableMethods.Contains)
41+
&& arguments[0].Type == typeof(byte[]))
42+
{
43+
var value = arguments[1] is SqlConstantExpression constantValue
44+
? _fbSqlExpressionFactory.Function("ASCII_CHAR", new[] { _fbSqlExpressionFactory.Constant((byte)constantValue.Value) }, false, new[] { false }, typeof(string))
45+
: _fbSqlExpressionFactory.Function("ASCII_CHAR", new[] { _fbSqlExpressionFactory.Convert(arguments[1], typeof(byte)) }, true, new[] { true }, typeof(string));
46+
47+
return _fbSqlExpressionFactory.GreaterThan(
48+
_fbSqlExpressionFactory.Function(
49+
"POSITION",
50+
new[] { value, arguments[0] },
51+
true,
52+
new[] { true, true },
53+
typeof(int)),
54+
_fbSqlExpressionFactory.Constant(0));
55+
}
4056
return null;
41-
42-
//if (method.IsGenericMethod
43-
// && method.GetGenericMethodDefinition().Equals(EnumerableMethods.Contains)
44-
// && arguments[0].Type == typeof(byte[]))
45-
//{
46-
// var source = arguments[0];
47-
// var sourceTypeMapping = source.TypeMapping;
48-
49-
// var value = arguments[1] is SqlConstantExpression constantValue
50-
// ? (SqlExpression)_fbSqlExpressionFactory.Constant(new[] { (byte)constantValue.Value }, sourceTypeMapping)
51-
// : _fbSqlExpressionFactory.Convert(arguments[1], typeof(byte[]), sourceTypeMapping);
52-
53-
// return _fbSqlExpressionFactory.GreaterThan(
54-
// _fbSqlExpressionFactory.Function(
55-
// "POSITION",
56-
// new[] { value, source },
57-
// true,
58-
// new[] { true, true },
59-
// typeof(int)),
60-
// _fbSqlExpressionFactory.Constant(0));
61-
//}
62-
//return null;
6357
}
6458
}
6559
}

0 commit comments

Comments
 (0)