예제 #1
0
 public SqlNumberNode Apply(SqlNumberNode left, SqlNumberNode right)
 {
     if (left.IsNumeric || right.IsNumeric)
     {
         return(ApplyNumeric(left.AsNumeric(), right.AsNumeric()));
     }
     if (left.IsBigint || right.IsBigint)
     {
         return(ApplyBigint(left.AsBigInt(), right.AsBigInt()));
     }
     return(ApplyInt(left, right));
 }
예제 #2
0
        private SqlNumberNode ApplyNumeric(SqlNumberNode left, SqlNumberNode right)
        {
            switch (Operator)
            {
            case "+": return(new SqlNumberNode(left.Numeric + right.Numeric));

            case "-": return(new SqlNumberNode(left.Numeric - right.Numeric));

            case "*": return(new SqlNumberNode(left.Numeric * right.Numeric));

            case "/": return(new SqlNumberNode(left.Numeric / right.Numeric));

            case "%": return(new SqlNumberNode(left.Numeric % right.Numeric));
            }

            throw new Exception($"Cannot apply operator {Operator} to operands of type numeric");
        }
예제 #3
0
        private SqlNumberNode ApplyInt(SqlNumberNode left, SqlNumberNode right)
        {
            switch (Operator)
            {
            case "+": return(new SqlNumberNode(left.Int + right.Int));

            case "-": return(new SqlNumberNode(left.Int - right.Int));

            case "*": return(new SqlNumberNode(left.Int * right.Int));

            case "/": return(new SqlNumberNode(left.Int / right.Int));

            case "%": return(new SqlNumberNode(left.Int % right.Int));

            case "&": return(new SqlNumberNode(left.Int & right.Int));

            case "^": return(new SqlNumberNode(left.Int ^ right.Int));

            case "|": return(new SqlNumberNode(left.Int | right.Int));
            }

            throw new Exception($"Cannot apply operator {Operator} to operands of type int");
        }