Skip to content

Commit

Permalink
More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cincuranet committed Dec 12, 2024
1 parent cca2c26 commit 935b0bf
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@ public override Task DateTimeOffset_to_unix_time_seconds(bool async)
return base.DateTimeOffset_to_unix_time_seconds(async);
}

[NotSupportedByProviderTheory]
[MemberData(nameof(IsAsyncData))]
public override Task Non_string_concat_uses_appropriate_type_mapping(bool async)
{
return base.Non_string_concat_uses_appropriate_type_mapping(async);
}

[Theory(Skip = "NETProvider#1008")]
[MemberData(nameof(IsAsyncData))]
public override Task Where_TimeOnly_IsBetween(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

namespace FirebirdSql.EntityFrameworkCore.Firebird.Query.ExpressionTranslators.Internal;

public class SqlServerDateOnlyMethodTranslator : IMethodCallTranslator
public class FbDateOnlyMethodTranslator : IMethodCallTranslator
{
readonly Dictionary<MethodInfo, string> _methodInfoDatePartMapping = new()
{
Expand All @@ -36,7 +36,7 @@ public class SqlServerDateOnlyMethodTranslator : IMethodCallTranslator

readonly ISqlExpressionFactory _sqlExpressionFactory;

public SqlServerDateOnlyMethodTranslator(ISqlExpressionFactory sqlExpressionFactory)
public FbDateOnlyMethodTranslator(ISqlExpressionFactory sqlExpressionFactory)
{
_sqlExpressionFactory = sqlExpressionFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class FbObjectToStringTranslator : IMethodCallTranslator
typeof(int),
typeof(long),
typeof(DateTime),
typeof(bool),
typeof(byte),
typeof(byte[]),
typeof(double),
Expand All @@ -59,18 +58,54 @@ public FbObjectToStringTranslator(FbSqlExpressionFactory fbSqlExpressionFactory)

public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments, IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
if (method.Name == nameof(ToString) && method.GetParameters().Length == 0)
if (instance == null || method.Name != nameof(ToString) || arguments.Count != 0)
{
var type = instance.Type.UnwrapNullableType();
if (SupportedTypes.Contains(type))
return null;
}

if (instance.TypeMapping?.ClrType == typeof(string))
{
return instance;
}

if (SupportedTypes.Contains(instance.Type))
{
return _fbSqlExpressionFactory.Convert(instance, typeof(string));
}
else if (instance.Type == typeof(Guid))
{
return _fbSqlExpressionFactory.Function("UUID_TO_CHAR", new[] { instance }, true, new[] { true }, typeof(string));
}
else if (instance.Type == typeof(bool))
{
if (instance is not ColumnExpression { IsNullable: false })
{
return _fbSqlExpressionFactory.Convert(instance, typeof(string));
return _fbSqlExpressionFactory.Case(
instance,
new[]
{
new CaseWhenClause(
_fbSqlExpressionFactory.Constant(false),
_fbSqlExpressionFactory.Constant(false.ToString())),
new CaseWhenClause(
_fbSqlExpressionFactory.Constant(true),
_fbSqlExpressionFactory.Constant(true.ToString()))
},
_fbSqlExpressionFactory.Constant(string.Empty));
}
else if (type == typeof(Guid))
else
{
return _fbSqlExpressionFactory.Function("UUID_TO_CHAR", new[] { instance }, true, new[] { true }, typeof(string));
return _fbSqlExpressionFactory.Case(
new[]
{
new CaseWhenClause(
instance,
_fbSqlExpressionFactory.Constant(true.ToString()))
},
_fbSqlExpressionFactory.Constant(false.ToString()));
}
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* https://github.com/FirebirdSQL/NETProvider/raw/master/license.txt.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* All Rights Reserved.
*/

//$Authors = Jiri Cincura ([email protected])

using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;

namespace FirebirdSql.EntityFrameworkCore.Firebird.Query.ExpressionTranslators.Internal;

public class FbTimeOnlyMethodTranslator : IMethodCallTranslator
{
static readonly MethodInfo FromDateTime = typeof(TimeOnly).GetRuntimeMethod(nameof(TimeOnly.FromDateTime), [typeof(DateTime)]);
static readonly MethodInfo FromTimeSpan = typeof(TimeOnly).GetRuntimeMethod(nameof(TimeOnly.FromTimeSpan), [typeof(TimeSpan)]);

readonly ISqlExpressionFactory _sqlExpressionFactory;

public FbTimeOnlyMethodTranslator(ISqlExpressionFactory sqlExpressionFactory)
{
_sqlExpressionFactory = sqlExpressionFactory;
}

public virtual SqlExpression Translate(
SqlExpression instance,
MethodInfo method,
IReadOnlyList<SqlExpression> arguments,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
if (method.DeclaringType != typeof(TimeOnly))
{
return null;
}

if ((method == FromDateTime || method == FromTimeSpan)
&& instance is null
&& arguments.Count == 1)
{
return _sqlExpressionFactory.Convert(arguments[0], typeof(TimeOnly));
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ protected override Expression VisitSqlConstant(SqlConstantExpression sqlConstant

protected override void GenerateEmptyProjection(SelectExpression selectExpression)
{
base.GenerateEmptyProjection(selectExpression);
Sql.Append("1 AS dummy");
if (selectExpression.Alias != null)
{
Sql.Append(" AS empty");
Expand Down

0 comments on commit 935b0bf

Please sign in to comment.