예제 #1
0
        internal static gsCompareOperator ToCompareOperator(this BooleanComparisonType compareType)
        {
            switch (compareType)
            {
            case BooleanComparisonType.Equals:
                return(gsCompareOperator.Equal);

            case BooleanComparisonType.GreaterThan:
                return(gsCompareOperator.Greater);

            case BooleanComparisonType.LessThan:
                return(gsCompareOperator.Less);

            case BooleanComparisonType.GreaterThanOrEqualTo:
                return(gsCompareOperator.GreaterOrEqual);

            case BooleanComparisonType.LessThanOrEqualTo:
                return(gsCompareOperator.LessOrEqual);

            case BooleanComparisonType.NotEqualToBrackets:
            case BooleanComparisonType.NotEqualToExclamation:
                return(gsCompareOperator.NotEqual);

            default:
                throw new NotSupportedException("Unsupported CompareOperator type");
            }
        }
        // TODO: use switch expression, expression bodied member
        public static bool Evaluate(BooleanComparisonType op, object left, object right)
        {
            switch (op)
            {
            case BooleanComparisonType.Equals:
                return(left != null && left.Equals(right));

            case BooleanComparisonType.NotEqualToBrackets:
            case BooleanComparisonType.NotEqualToExclamation:
                return(left == null || !left.Equals(right));

            case BooleanComparisonType.GreaterThan:
                // TODO: handle numeric conversions properly
                if (left is int i && right is int j)
                {
                    return(i > j);
                }
                if (left is decimal m && right is decimal n)
                {
                    return(m > n);
                }
                return(string.Compare(left.ToString(), right.ToString()) > 0);

            case BooleanComparisonType.GreaterThanOrEqualTo:
                if (left is int i2 && right is int j2)
                {
                    return(i2 >= j2);
                }
                if (left is decimal m2 && right is decimal n2)
                {
                    return(m2 >= n2);
                }
                return(string.Compare(left.ToString(), right.ToString()) >= 0);

            case BooleanComparisonType.LessThan:
                if (left is int i3 && right is int j3)
                {
                    return(i3 < j3);
                }
                if (left is decimal m3 && right is decimal n3)
                {
                    return(m3 < n3);
                }
                return(string.Compare(left.ToString(), right.ToString()) < 0);

            case BooleanComparisonType.LessThanOrEqualTo:
                if (left is int i4 && right is int j4)
                {
                    return(i4 <= j4);
                }
                if (left is decimal m4 && right is decimal n4)
                {
                    return(m4 <= n4);
                }
                return(string.Compare(left.ToString(), right.ToString()) <= 0);

            default:
                throw FeatureNotSupportedException.Value(op);
            }
        }
        public static string BooleanComparisonType(BooleanComparisonType ctype)
        {
            switch (ctype)
            {
            case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.Equals:
                return("=");

            case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.GreaterThan:
                return(">");

            case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.GreaterThanOrEqualTo:
                return(">=");

            case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.LessThan:
                return("<");

            case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.LessThanOrEqualTo:
                return("<=");

            case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.NotEqualToBrackets:
                return("<>");

            case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.NotEqualToExclamation:
                return("!=");

            case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.NotGreaterThan:
                return("!>");

            case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.NotLessThan:
                return("!<");

            default:
                throw new GraphViewException("Invalid boolean expression type");
            }
        }
 private static cs.CodeBinaryOperatorType ConvertToBinaryOperatorType(BooleanComparisonType comparisonType)
 {
     if (comparisonType == BooleanComparisonType.Equals)
     {
         return(cs.CodeBinaryOperatorType.ValueEquality);
     }
     if (comparisonType == BooleanComparisonType.NotEqualToBrackets)
     {
         return(cs.CodeBinaryOperatorType.IdentityInequality);
     }
     if (comparisonType == BooleanComparisonType.GreaterThan)
     {
         return(cs.CodeBinaryOperatorType.GreaterThan);
     }
     if (comparisonType == BooleanComparisonType.GreaterThanOrEqualTo)
     {
         return(cs.CodeBinaryOperatorType.GreaterThanOrEqual);
     }
     if (comparisonType == BooleanComparisonType.LessThan)
     {
         return(cs.CodeBinaryOperatorType.LessThan);
     }
     if (comparisonType == BooleanComparisonType.LessThanOrEqualTo)
     {
         return(cs.CodeBinaryOperatorType.LessThanOrEqual);
     }
     if (comparisonType == BooleanComparisonType.NotEqualToExclamation)
     {
         return(cs.CodeBinaryOperatorType.IdentityInequality);
     }
     throw new NotImplementedException("" + comparisonType);
 }
예제 #5
0
 private void checkHasNullVariableReference(
     ScalarExpression firstExpression,
     ScalarExpression secondExpression,
     BooleanComparisonType comparisonType)
 {
     checkHasNullVariableReference(firstExpression, comparisonType);
     checkHasNullVariableReference(secondExpression, comparisonType);
 }
예제 #6
0
 private void checkHasNullLiteral(
     ScalarExpression firstExpression,
     ScalarExpression secondExpression,
     BooleanComparisonType comparisonType)
 {
     if (firstExpression is NullLiteral ||
         secondExpression is NullLiteral)
     {
         checkComparisonType(comparisonType);
     }
 }
예제 #7
0
 private void checkHasNullLiteral(
     ScalarExpression firstExpression,
     ScalarExpression secondExpression,
     BooleanComparisonType comparisonType)
 {
     if (firstExpression is NullLiteral ||
        secondExpression is NullLiteral)
     {
         checkComparisonType(comparisonType);
     }
 }
예제 #8
0
 private void checkComparisonType(BooleanComparisonType comparisonType)
 {
     switch (comparisonType)
     {
     case BooleanComparisonType.Equals:
     case BooleanComparisonType.NotEqualToBrackets:
     case BooleanComparisonType.NotEqualToExclamation:
         IsSuspected = true;
         break;
     }
 }
예제 #9
0
 private void checkComparisonType(BooleanComparisonType comparisonType)
 {
     switch (comparisonType)
     {
         case BooleanComparisonType.Equals:
         case BooleanComparisonType.NotEqualToBrackets:
         case BooleanComparisonType.NotEqualToExclamation:
             IsSuspected = true;
             break;
     }
 }
예제 #10
0
        public override object VisitBoolean_comparison_expression([NotNull] KoraliumParser.Boolean_comparison_expressionContext context)
        {
            var typeNode = context.boolean_comparison_type();

            if (typeNode == null)
            {
                throw new SqlParserException("Boolean comparison without any type");
            }

            var comparisionOperation = typeNode.GetText();
            BooleanComparisonType booleanComparisonType = BooleanComparisonType.Equals;

            switch (comparisionOperation)
            {
            case "=":
            case "==":
                booleanComparisonType = BooleanComparisonType.Equals;
                break;

            case ">":
                booleanComparisonType = BooleanComparisonType.GreaterThan;
                break;

            case "<":
                booleanComparisonType = BooleanComparisonType.LessThan;
                break;

            case ">=":
            case "!<":
                booleanComparisonType = BooleanComparisonType.GreaterThanOrEqualTo;
                break;

            case "!=":
            case "<>":
                booleanComparisonType = BooleanComparisonType.NotEqualTo;
                break;

            case "<=":
            case "!>":
                booleanComparisonType = BooleanComparisonType.LessThanOrEqualTo;
                break;
            }

            return(new BooleanComparisonExpression()
            {
                Left = Visit(context.left) as ScalarExpression,
                Right = Visit(context.right) as ScalarExpression,
                Type = booleanComparisonType
            });
        }
예제 #11
0
        private void checkHasNullVariableReference(ScalarExpression expression, BooleanComparisonType comparisonType)
        {
            var reference = expression as VariableReference;

            if (reference == null)
            {
                return;
            }

            var parameterName = reference.Name;

            if (!_declaredNullVariables.Contains(parameterName) && !NullVariableNames.Contains(parameterName))
            {
                return;
            }

            checkComparisonType(comparisonType);
        }
예제 #12
0
 private BooleanComparisonExpression GetBooleanComparisonExpression(BooleanComparisonType booleanComparisonType)
 {
     return(new BooleanComparisonExpression()
     {
         Left = new ColumnReference()
         {
             Identifiers = new List <string>()
             {
                 "c1"
             }
         },
         Right = new IntegerLiteral()
         {
             Value = 3
         },
         Type = booleanComparisonType
     });
 }
예제 #13
0
 public ComparisonFunction(ScalarFunction f1, ScalarFunction f2, BooleanComparisonType comparisonType)
 {
     firstScalarFunction  = f1;
     secondScalarFunction = f2;
     this.comparisonType  = comparisonType;
 }
예제 #14
0
 internal static WBooleanComparisonExpression GetBooleanComparisonExpr(WScalarExpression firstExpr,
                                                                       WScalarExpression secondExpr, BooleanComparisonType type)
 {
     return(new WBooleanComparisonExpression()
     {
         ComparisonType = type,
         FirstExpr = firstExpr,
         SecondExpr = secondExpr
     });
 }
예제 #15
0
 public static string BooleanComparisonType(BooleanComparisonType ctype)
 {
     switch (ctype)
     {
         case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.Equals:
             return "=";
         case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.GreaterThan:
             return ">";
         case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.GreaterThanOrEqualTo:
             return ">=";
         case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.LessThan:
             return "<";
         case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.LessThanOrEqualTo:
             return "<=";
         case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.NotEqualToBrackets:
             return "<>";
         case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.NotEqualToExclamation:
             return "!=";
         case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.NotGreaterThan:
             return "!>";
         case Microsoft.SqlServer.TransactSql.ScriptDom.BooleanComparisonType.NotLessThan:
             return "!<";
         default:
             throw new GraphViewException("Invalid boolean expression type");
     }
 }
예제 #16
0
        private void checkHasNullVariableReference(ScalarExpression expression, BooleanComparisonType comparisonType)
        {
            var reference = expression as VariableReference;
            if (reference == null)
                return;

            var parameterName = reference.Name;
            if (!_declaredNullVariables.Contains(parameterName) && !NullVariableNames.Contains(parameterName))
                return;

            checkComparisonType(comparisonType);
        }
예제 #17
0
 private void checkHasNullVariableReference(
     ScalarExpression firstExpression,
     ScalarExpression secondExpression,
     BooleanComparisonType comparisonType)
 {
     checkHasNullVariableReference(firstExpression, comparisonType);
     checkHasNullVariableReference(secondExpression, comparisonType);
 }
예제 #18
0
        public static bool Compare(string value1, string value2, JsonDataType targetType, BooleanComparisonType comparisonType)
        {
            switch (targetType)
            {
            case JsonDataType.Boolean:
                bool bool_value1, bool_value2;
                if (bool.TryParse(value1, out bool_value1) && bool.TryParse(value2, out bool_value2))
                {
                    switch (comparisonType)
                    {
                    case BooleanComparisonType.Equals:
                        return(bool_value1 == bool_value2);

                    case BooleanComparisonType.NotEqualToBrackets:
                    case BooleanComparisonType.NotEqualToExclamation:
                        return(bool_value1 != bool_value2);

                    default:
                        throw new QueryCompilationException("Operator " + comparisonType.ToString() + " cannot be applied to operands of type \"boolean\".");
                    }
                }
                else
                {
                    return(false);
                }

            case JsonDataType.Bytes:
                switch (comparisonType)
                {
                case BooleanComparisonType.Equals:
                    return(value1 == value2);

                case BooleanComparisonType.NotEqualToBrackets:
                case BooleanComparisonType.NotEqualToExclamation:
                    return(value1 != value2);

                default:
                    return(false);
                }

            case JsonDataType.Int:
                int int_value1, int_value2;
                if (int.TryParse(value1, out int_value1) && int.TryParse(value2, out int_value2))
                {
                    switch (comparisonType)
                    {
                    case BooleanComparisonType.Equals:
                        return(int_value1 == int_value2);

                    case BooleanComparisonType.GreaterThan:
                        return(int_value1 > int_value2);

                    case BooleanComparisonType.GreaterThanOrEqualTo:
                        return(int_value1 >= int_value2);

                    case BooleanComparisonType.LessThan:
                        return(int_value1 < int_value2);

                    case BooleanComparisonType.LessThanOrEqualTo:
                        return(int_value1 <= int_value2);

                    case BooleanComparisonType.NotEqualToBrackets:
                    case BooleanComparisonType.NotEqualToExclamation:
                        return(int_value1 != int_value2);

                    case BooleanComparisonType.NotGreaterThan:
                        return(!(int_value1 > int_value2));

                    case BooleanComparisonType.NotLessThan:
                        return(!(int_value1 < int_value2));

                    default:
                        throw new QueryCompilationException("Operator " + comparisonType.ToString() + " cannot be applied to operands of type \"int\".");
                    }
                }
                else
                {
                    return(false);
                }

            case JsonDataType.Long:
                long long_value1, long_value2;
                if (long.TryParse(value1, out long_value1) && long.TryParse(value2, out long_value2))
                {
                    switch (comparisonType)
                    {
                    case BooleanComparisonType.Equals:
                        return(long_value1 == long_value2);

                    case BooleanComparisonType.GreaterThan:
                        return(long_value1 > long_value2);

                    case BooleanComparisonType.GreaterThanOrEqualTo:
                        return(long_value1 >= long_value2);

                    case BooleanComparisonType.LessThan:
                        return(long_value1 < long_value2);

                    case BooleanComparisonType.LessThanOrEqualTo:
                        return(long_value1 <= long_value2);

                    case BooleanComparisonType.NotEqualToBrackets:
                    case BooleanComparisonType.NotEqualToExclamation:
                        return(long_value1 != long_value2);

                    case BooleanComparisonType.NotGreaterThan:
                        return(!(long_value1 > long_value2));

                    case BooleanComparisonType.NotLessThan:
                        return(!(long_value1 < long_value2));

                    default:
                        throw new QueryCompilationException("Operator " + comparisonType.ToString() + " cannot be applied to operands of type \"long\".");
                    }
                }
                else
                {
                    return(false);
                }

            case JsonDataType.Double:
                double double_value1, double_value2;
                if (double.TryParse(value1, out double_value1) && double.TryParse(value2, out double_value2))
                {
                    switch (comparisonType)
                    {
                    case BooleanComparisonType.Equals:
                        return(double_value1 == double_value2);

                    case BooleanComparisonType.GreaterThan:
                        return(double_value1 > double_value2);

                    case BooleanComparisonType.GreaterThanOrEqualTo:
                        return(double_value1 >= double_value2);

                    case BooleanComparisonType.LessThan:
                        return(double_value1 < double_value2);

                    case BooleanComparisonType.LessThanOrEqualTo:
                        return(double_value1 <= double_value2);

                    case BooleanComparisonType.NotEqualToBrackets:
                    case BooleanComparisonType.NotEqualToExclamation:
                        return(double_value1 != double_value2);

                    case BooleanComparisonType.NotGreaterThan:
                        return(!(double_value1 > double_value2));

                    case BooleanComparisonType.NotLessThan:
                        return(!(double_value1 < double_value2));

                    default:
                        throw new QueryCompilationException("Operator " + comparisonType.ToString() + " cannot be applied to operands of type \"double\".");
                    }
                }
                else
                {
                    return(false);
                }

            case JsonDataType.Float:
                float float_value1, float_value2;
                if (float.TryParse(value1, out float_value1) && float.TryParse(value2, out float_value2))
                {
                    switch (comparisonType)
                    {
                    case BooleanComparisonType.Equals:
                        return(float_value1 == float_value2);

                    case BooleanComparisonType.GreaterThan:
                        return(float_value1 > float_value2);

                    case BooleanComparisonType.GreaterThanOrEqualTo:
                        return(float_value1 >= float_value2);

                    case BooleanComparisonType.LessThan:
                        return(float_value1 < float_value2);

                    case BooleanComparisonType.LessThanOrEqualTo:
                        return(float_value1 <= float_value2);

                    case BooleanComparisonType.NotEqualToBrackets:
                    case BooleanComparisonType.NotEqualToExclamation:
                        return(float_value1 != float_value2);

                    case BooleanComparisonType.NotGreaterThan:
                        return(!(float_value1 > float_value2));

                    case BooleanComparisonType.NotLessThan:
                        return(!(float_value1 < float_value2));

                    default:
                        throw new QueryCompilationException("Operator " + comparisonType.ToString() + " cannot be applied to operands of type \"float\".");
                    }
                }
                else
                {
                    return(false);
                }

            case JsonDataType.String:
                switch (comparisonType)
                {
                case BooleanComparisonType.Equals:
                    return(value1 == value2);

                case BooleanComparisonType.GreaterThan:
                case BooleanComparisonType.GreaterThanOrEqualTo:
                    return(value1.CompareTo(value2) > 0);

                case BooleanComparisonType.LessThan:
                case BooleanComparisonType.LessThanOrEqualTo:
                    return(value1.CompareTo(value2) > 0);

                case BooleanComparisonType.NotEqualToBrackets:
                case BooleanComparisonType.NotEqualToExclamation:
                    return(value1 != value2);

                case BooleanComparisonType.NotGreaterThan:
                    return(value1.CompareTo(value2) <= 0);

                case BooleanComparisonType.NotLessThan:
                    return(value1.CompareTo(value2) >= 0);

                default:
                    throw new QueryCompilationException("Operator " + comparisonType.ToString() + " cannot be applied to operands of type \"string\".");
                }

            case JsonDataType.Date:
                throw new NotImplementedException();

            case JsonDataType.Null:
                return(false);

            default:
                throw new QueryCompilationException("Unsupported data type.");
            }
        }