Exemplo n.º 1
0
        public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments)
        {
            if (!method.Equals(MethodInfo))
            {
                return(null);
            }

            var patternExpression  = arguments[0];
            var endsWithExpression = _fbSqlExpressionFactory.Equal(
                _fbSqlExpressionFactory.Function(
                    "RIGHT",
                    new[] {
                instance,
                _fbSqlExpressionFactory.Function(
                    "CHARACTER_LENGTH",
                    new[] { patternExpression },
                    typeof(int))
            },
                    instance.Type),
                patternExpression);

            return(patternExpression is SqlConstantExpression sqlConstantExpression
                                ? (string)sqlConstantExpression.Value == string.Empty
                                        ? (SqlExpression)_fbSqlExpressionFactory.Constant(true)
                                        : endsWithExpression
                                : _fbSqlExpressionFactory.OrElse(
                       endsWithExpression,
                       _fbSqlExpressionFactory.Equal(
                           patternExpression,
                           _fbSqlExpressionFactory.Constant(string.Empty))));
        }
        public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments)
        {
            if (!method.Equals(MethodInfo))
            {
                return(null);
            }

            var patternExpression  = arguments[0];
            var positionExpression = _fbSqlExpressionFactory.GreaterThan(
                _fbSqlExpressionFactory.Function(
                    "POSITION",
                    new[] { patternExpression, instance },
                    typeof(int)),
                _fbSqlExpressionFactory.Constant(0));

            return(patternExpression is SqlConstantExpression sqlConstantExpression
                                ? ((string)sqlConstantExpression.Value)?.Length == 0
                                        ? (SqlExpression)_fbSqlExpressionFactory.Constant(true)
                                        : positionExpression
                                : _fbSqlExpressionFactory.OrElse(
                       positionExpression,
                       _fbSqlExpressionFactory.Equal(
                           patternExpression,
                           _fbSqlExpressionFactory.Constant(string.Empty))));
        }
Exemplo n.º 3
0
        public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
        {
            if (!method.Equals(MethodInfo))
            {
                return(null);
            }

            var patternExpression  = _fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0]);
            var positionExpression = _fbSqlExpressionFactory.GreaterThan(
                _fbSqlExpressionFactory.Function(
                    "POSITION",
                    new[] { patternExpression, instance },
                    true,
                    new[] { true, true },
                    typeof(int)),
                _fbSqlExpressionFactory.Constant(0));

            return(patternExpression is SqlConstantExpression sqlConstantExpression
                                ? ((string)sqlConstantExpression.Value)?.Length == 0
                                        ? (SqlExpression)_fbSqlExpressionFactory.Constant(true)
                                        : positionExpression
                                : _fbSqlExpressionFactory.OrElse(
                       positionExpression,
                       _fbSqlExpressionFactory.Equal(
                           patternExpression,
                           _fbSqlExpressionFactory.Constant(string.Empty))));
        }
    public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
    {
        if (!method.Equals(MethodInfo))
        {
            return(null);
        }

        var patternExpression  = _fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0]);
        var endsWithExpression = _fbSqlExpressionFactory.Equal(
            _fbSqlExpressionFactory.ApplyDefaultTypeMapping(_fbSqlExpressionFactory.Function(
                                                                "RIGHT",
                                                                new[] {
            instance,
            _fbSqlExpressionFactory.Function(
                "CHAR_LENGTH",
                new[] { patternExpression },
                true,
                new[] { true },
                typeof(int))
        },
                                                                true,
                                                                new[] { true, true },
                                                                instance.Type)),
            patternExpression);

        return(patternExpression is SqlConstantExpression sqlConstantExpression
                        ? (string)sqlConstantExpression.Value == string.Empty
                                ? (SqlExpression)_fbSqlExpressionFactory.Constant(true)
                                : endsWithExpression
                        : _fbSqlExpressionFactory.OrElse(
                   endsWithExpression,
                   _fbSqlExpressionFactory.Equal(
                       patternExpression,
                       _fbSqlExpressionFactory.Constant(string.Empty))));
    }
 public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments)
 {
     if (method.DeclaringType == typeof(string) && method.Name == nameof(string.IndexOf))
     {
         return(_fbSqlExpressionFactory.Subtract(
                    _fbSqlExpressionFactory.Function("POSITION", new[] { arguments[0], instance }.Concat(arguments.Skip(1)), typeof(int)),
                    _fbSqlExpressionFactory.Constant(1)));
     }
     return(null);
 }
 public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
 {
     if (method.DeclaringType == typeof(string) && method.Name == nameof(string.IndexOf))
     {
         var args = new[] { arguments[0], instance }.Concat(arguments.Skip(1));
         return(_fbSqlExpressionFactory.Subtract(
                    _fbSqlExpressionFactory.Function("POSITION", args, true, args.Select(_ => true), typeof(int)),
                    _fbSqlExpressionFactory.Constant(1)));
     }
     return(null);
 }
Exemplo n.º 7
0
        public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments)
        {
            if (!(method.Equals(SubstringOnlyStartMethod) || method.Equals(SubstringStartAndLengthMethod)))
            {
                return(null);
            }

            var fromExpression = _fbSqlExpressionFactory.Add(arguments[0], _fbSqlExpressionFactory.Constant(1));
            var forExpression  = arguments.Count == 2 ? arguments[1] : null;

            return(_fbSqlExpressionFactory.Substring(instance, fromExpression, forExpression));
        }
        public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
        {
            if (!method.Equals(StartsWithMethod))
            {
                return(null);
            }

            var patternExpression = arguments[0];

            var startsWithExpression = _fbSqlExpressionFactory.AndAlso(
                _fbSqlExpressionFactory.Like(
                    instance,
                    _fbSqlExpressionFactory.Add(patternExpression, _fbSqlExpressionFactory.Constant("%"))),
                _fbSqlExpressionFactory.Equal(
                    _fbSqlExpressionFactory.Function(
                        "LEFT",
                        new[] {
                instance,
                _fbSqlExpressionFactory.Function(
                    "CHAR_LENGTH",
                    new[] { patternExpression },
                    true,
                    new[] { true },
                    typeof(int))
            },
                        true,
                        new[] { true, true },
                        instance.Type),
                    patternExpression));

            return(patternExpression is SqlConstantExpression sqlConstantExpression
                                ? (string)sqlConstantExpression.Value == string.Empty
                                        ? (SqlExpression)_fbSqlExpressionFactory.Constant(true)
                                        : startsWithExpression
                                : _fbSqlExpressionFactory.OrElse(
                       startsWithExpression,
                       _fbSqlExpressionFactory.Equal(
                           patternExpression,
                           _fbSqlExpressionFactory.Constant(string.Empty))));
        }
	public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments, IDiagnosticsLogger<DbLoggerCategory.Query> logger)
	{
		if (!method.Equals(MethodInfo))
			return null;

		var argument = _fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0]);
		return _fbSqlExpressionFactory.Function(
			"RIGHT",
			new[] { argument, _fbSqlExpressionFactory.Constant(1) },
			true,
			new[] { true, false },
			typeof(string));
	}
 public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
 {
     if (SupportedMethodTranslations.TryGetValue(method, out var sqlFunctionName))
     {
         return(_fbSqlExpressionFactory.Function(sqlFunctionName, arguments, true, arguments.Select(_ => true), method.ReturnType));
     }
     if (TruncateMethodInfos.Contains(method))
     {
         return(_fbSqlExpressionFactory.Function(
                    "TRUNC",
                    new[] { arguments[0], _fbSqlExpressionFactory.Constant(0) },
                    true,
                    new[] { true, default },
        public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
        {
            if (!method.Equals(MethodInfo))
            {
                return(null);
            }

            var argument = arguments[0];

            return(_fbSqlExpressionFactory.Function(
                       "LEFT",
                       new[] { argument, _fbSqlExpressionFactory.Constant(1) },
                       true,
                       new[] { true, default },
Exemplo n.º 12
0
        public SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType)
        {
            if (!MemberDatePartMapping.TryGetValue(member, out var part))
            {
                return(null);
            }

            var result = (SqlExpression)_fbSqlExpressionFactory.Extract(part, instance);

            if (part == YearDayPart)
            {
                result = _fbSqlExpressionFactory.Add(result, _fbSqlExpressionFactory.Constant(1));
            }
            return(result);
        }
Exemplo n.º 13
0
 public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments)
 {
     if (SupportedMethodTranslations.TryGetValue(method, out var sqlFunctionName))
     {
         return(_fbSqlExpressionFactory.Function(sqlFunctionName, arguments, method.ReturnType));
     }
     if (TruncateMethodInfos.Contains(method))
     {
         return(_fbSqlExpressionFactory.Function(
                    "TRUNC",
                    new[] { arguments[0], _fbSqlExpressionFactory.Constant(0) },
                    method.ReturnType));
     }
     if (RoundMethodInfos.Contains(method))
     {
         return(_fbSqlExpressionFactory.Function(
                    "ROUND",
                    arguments.Count == 1
                                         ? new[] { arguments[0], _fbSqlExpressionFactory.Constant(0) }
                                         : new[] { arguments[0], arguments[1] },
                    method.ReturnType));
     }
     return(null);
 }
Exemplo n.º 14
0
        public SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
        {
            if (!MemberMapping.TryGetValue(member, out var part))
            {
                return(null);
            }

            var result = (SqlExpression)_fbSqlExpressionFactory.Extract(part, instance);

            if (part == YearDayPart)
            {
                result = _fbSqlExpressionFactory.Add(result, _fbSqlExpressionFactory.Constant(1));
            }
            return(result);
        }
Exemplo n.º 15
0
        public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
        {
            if (!method.Equals(IsNullOrWhiteSpaceMethod))
            {
                return(null);
            }

            var argument = arguments[0];

            return(_fbSqlExpressionFactory.OrElse(
                       _fbSqlExpressionFactory.IsNull(argument),
                       _fbSqlExpressionFactory.Equal(
                           _fbSqlExpressionFactory.Function("TRIM", new[] { argument }, true, new[] { true }, typeof(string)),
                           _fbSqlExpressionFactory.Constant(string.Empty))
                       ));
        }
 public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
 {
     if (method.DeclaringType == typeof(string) && method.Name == nameof(string.IndexOf))
     {
         var args = new List <SqlExpression>();
         args.Add(_fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0]));
         args.Add(instance);
         foreach (var a in arguments.Skip(1))
         {
             args.Add(_fbSqlExpressionFactory.ApplyDefaultTypeMapping(a));
         }
         return(_fbSqlExpressionFactory.Subtract(
                    _fbSqlExpressionFactory.Function("POSITION", args, true, Enumerable.Repeat(true, args.Count), typeof(int)),
                    _fbSqlExpressionFactory.Constant(1)));
     }
     return(null);
 }
        public SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
        {
            if (!MemberMapping.TryGetValue(member, out var part))
            {
                return(null);
            }

            var result = (SqlExpression)_fbSqlExpressionFactory.SpacedFunction(
                "EXTRACT",
                new[] { _fbSqlExpressionFactory.Fragment(part), _fbSqlExpressionFactory.Fragment("FROM"), instance },
                true,
                new[] { false, false, true },
                typeof(int));

            if (part == YearDayPart)
            {
                result = _fbSqlExpressionFactory.Add(result, _fbSqlExpressionFactory.Constant(1));
            }
            return(result);
        }
        public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
        {
            if (method.IsGenericMethod &&
                method.GetGenericMethodDefinition().Equals(EnumerableMethods.Contains) &&
                arguments[0].Type == typeof(byte[]))
            {
                var value = arguments[1] is SqlConstantExpression constantValue
                                        ? _fbSqlExpressionFactory.Function("ASCII_CHAR", new[] { _fbSqlExpressionFactory.Constant((byte)constantValue.Value) }, false, new[] { false }, typeof(string))
                                        : _fbSqlExpressionFactory.Function("ASCII_CHAR", new[] { _fbSqlExpressionFactory.Convert(_fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[1]), typeof(byte)) }, true, new[] { true }, typeof(string));

                return(_fbSqlExpressionFactory.GreaterThan(
                           _fbSqlExpressionFactory.Function(
                               "POSITION",
                               new[] { value, _fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0]) },
                               true,
                               new[] { true, true },
                               typeof(int)),
                           _fbSqlExpressionFactory.Constant(0)));
            }
            return(null);
        }
Exemplo n.º 19
0
        public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
        {
            if (!(method.Equals(SubstringOnlyStartMethod) || method.Equals(SubstringStartAndLengthMethod)))
            {
                return(null);
            }

            var fromExpression     = _fbSqlExpressionFactory.ApplyDefaultTypeMapping(_fbSqlExpressionFactory.Add(arguments[0], _fbSqlExpressionFactory.Constant(1)));
            var forExpression      = arguments.Count == 2 ? _fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[1]) : null;
            var substringArguments = forExpression != null
                                ? new[] { instance, _fbSqlExpressionFactory.Fragment("FROM"), fromExpression, _fbSqlExpressionFactory.Fragment("FOR"), forExpression }
                                : new[] { instance, _fbSqlExpressionFactory.Fragment("FROM"), fromExpression };
            var nullability = forExpression != null
                                ? new[] { true, false, true, false, true }
                                : new[] { true, false, true };

            return(_fbSqlExpressionFactory.SpacedFunction(
                       "SUBSTRING",
                       substringArguments,
                       true,
                       nullability,
                       typeof(string)));
        }
Exemplo n.º 20
0
 public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
 {
     if (SupportedMethodTranslations.TryGetValue(method, out var sqlFunctionName))
     {
         return(_fbSqlExpressionFactory.Function(sqlFunctionName, arguments, true, arguments.Select(_ => true), method.ReturnType));
     }
     if (TruncateMethodInfos.Contains(method))
     {
         return(_fbSqlExpressionFactory.ApplyDefaultTypeMapping(_fbSqlExpressionFactory.Function(
                                                                    "TRUNC",
                                                                    new[] { _fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0]), _fbSqlExpressionFactory.Constant(0) },
                                                                    true,
                                                                    new[] { true, false },
                                                                    method.ReturnType)));
     }
     if (RoundMethodInfos.Contains(method))
     {
         var roundArguments = arguments.Count == 1
                             ? new[] { _fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0]), _fbSqlExpressionFactory.Constant(0) }
                             : new[] { _fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0]), _fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[1]) };
         var nullability = arguments.Count == 1
                             ? new[] { true, false }
                             : new[] { true, true };
         return(_fbSqlExpressionFactory.ApplyDefaultTypeMapping(_fbSqlExpressionFactory.Function(
                                                                    "ROUND",
                                                                    roundArguments,
                                                                    true,
                                                                    nullability,
                                                                    method.ReturnType)));
     }
     return(null);
 }