Skip to content

Commit

Permalink
Clean up PR dotnet#22497
Browse files Browse the repository at this point in the history
  • Loading branch information
bricelam committed Oct 30, 2020
1 parent 939e30d commit 050f647
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public SqliteMethodCallTranslatorProvider([NotNull] RelationalMethodCallTranslat
new SqliteByteArrayMethodTranslator(sqlExpressionFactory),
new SqliteDateTimeAddTranslator(sqlExpressionFactory),
new SqliteMathTranslator(sqlExpressionFactory),
new SqliteRegexTranslator(sqlExpressionFactory),
new SqliteRegexMethodTranslator(sqlExpressionFactory),
new SqliteStringMethodTranslator(sqlExpressionFactory)
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,34 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public class SqliteRegexTranslator : IMethodCallTranslator
public class SqliteRegexMethodTranslator : IMethodCallTranslator
{
private readonly static MethodInfo _regexIsMatchMethodInfo
= typeof(Regex).GetRuntimeMethod(nameof(Regex.IsMatch), new Type[] { typeof(string), typeof(string) });

private readonly ISqlExpressionFactory _sqlExpressionFactory;
private readonly static MethodInfo regexIsMatchMethod = typeof(Regex).GetMethod(nameof(Regex.IsMatch), new Type[] { typeof(string), typeof(string) });

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public SqliteRegexTranslator([NotNull] ISqlExpressionFactory sqlExpressionFactory)
public SqliteRegexMethodTranslator([NotNull] ISqlExpressionFactory sqlExpressionFactory)
{
Check.NotNull(sqlExpressionFactory, nameof(sqlExpressionFactory));

_sqlExpressionFactory = sqlExpressionFactory;
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual SqlExpression Translate(SqlExpression instance,
public virtual SqlExpression Translate(
SqlExpression instance,
MethodInfo method,
IReadOnlyList<SqlExpression> arguments,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
Expand All @@ -49,13 +55,13 @@ public virtual SqlExpression Translate(SqlExpression instance,
Check.NotNull(arguments, nameof(arguments));
Check.NotNull(logger, nameof(logger));


if (method.Equals(regexIsMatchMethod))
if (method.Equals(_regexIsMatchMethodInfo))
{
return _sqlExpressionFactory.Function("regexp",
return _sqlExpressionFactory.Function(
"regexp",
new[] { arguments[1], arguments[0] },
false,
new[] { false, false },
nullable: true,
argumentsPropagateNullability: new[] { true, true },
typeof(bool),
arguments[0].TypeMapping);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,14 @@ private void InitializeDbConnection(DbConnection connection)
sqliteConnection.DefaultTimeout = _commandTimeout.Value;
}

sqliteConnection.CreateFunction<string, string, bool>(
sqliteConnection.CreateFunction<string, string, bool?>(
"regexp",
(pattern, input) =>
{
if (input == null || pattern == null)
if (input == null
|| pattern == null)
{
return false;
return null;
}
return Regex.IsMatch(input, pattern);
Expand All @@ -146,7 +147,8 @@ private void InitializeDbConnection(DbConnection connection)
return Convert.ToDouble(dividend, CultureInfo.InvariantCulture)
% Convert.ToDouble(divisor, CultureInfo.InvariantCulture);
});
},
isDeterministic: true);

sqliteConnection.CreateFunction(
name: "ef_add",
Expand Down Expand Up @@ -176,7 +178,6 @@ private void InitializeDbConnection(DbConnection connection)
isDeterministic: true);
}
else

{
_logger.UnexpectedConnectionTypeWarning(connection.GetType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,11 @@ public override Task Int_Compare_to_simple_zero(bool async)
return base.Int_Compare_to_simple_zero(async);
}

public override Task Regex_IsMatch_MethodCall(bool async)
{
return AssertTranslationFailed(() => base.Regex_IsMatch_MethodCall(async));
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,8 @@ public virtual Task Projecting_Math_Truncate_and_ordering_by_it_twice3(bool asyn
[MemberData(nameof(IsAsyncData))]
public virtual Task Regex_IsMatch_MethodCall(bool async)
{
return AssertQuery(async,
return AssertQuery(
async,
ss => ss.Set<Customer>().Where(o => Regex.IsMatch(o.CustomerID, @"^T")),
entryCount: 6);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,7 @@ public override async Task Projecting_Math_Truncate_and_ordering_by_it_twice3(bo
//WHERE [o].[OrderID] < 10250
//ORDER BY [A] DESC");
}

public override Task Regex_IsMatch_MethodCall(bool async)
{
return AssertTranslationFailed(() => base.Regex_IsMatch_MethodCall(async));
Expand Down

0 comments on commit 050f647

Please sign in to comment.