public static void VisitBinary() { var exp = SqlExpression.Binary(SqlExpressionType.Add, SqlExpression.Constant(SqlObject.Integer(22)), SqlExpression.Constant(SqlObject.Integer(344))); Visit(exp); }
public override SqlBinaryExpression Deserialize(BinaryReader reader) { var left = ReadExpression(reader); var exptype = (SqlExpressionType)reader.ReadByte(); var right = ReadExpression(reader); return(SqlExpression.Binary(left, exptype, right)); }
public void CreateInvalidQuantify(SqlExpressionType expressionType, SqlExpressionType opType) { var left = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(212))); var right = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(array))); var binary = SqlExpression.Binary(opType, left, right); Assert.Throws <ArgumentException>(() => SqlExpression.Quantify(expressionType, binary)); }
public static void GetBinaryString(SqlExpressionType expressionType, object value1, object value2, string expected) { var obj1 = SqlObject.New(SqlValueUtil.FromObject(value1)); var obj2 = SqlObject.New(SqlValueUtil.FromObject(value2)); var exp = SqlExpression.Binary(expressionType, SqlExpression.Constant(obj1), SqlExpression.Constant(obj2)); var s = exp.ToString(); Assert.Equal(expected, s); }
public static void SerializeBinary(SqlExpressionType type, object value1, object value2) { var binary = SqlExpression.Binary(type, SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value1))), SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value2)))); var result = BinarySerializeUtil.Serialize(binary); Assert.Equal(binary.ExpressionType, result.ExpressionType); Assert.Equal(binary.Left.ExpressionType, result.Left.ExpressionType); Assert.Equal(binary.Right.ExpressionType, result.Right.ExpressionType); }
public static void CreateBinary(SqlExpressionType expressionType, object value1, object value2) { var obj1 = SqlObject.New(SqlValueUtil.FromObject(value1)); var obj2 = SqlObject.New(SqlValueUtil.FromObject(value2)); var exp = SqlExpression.Binary(expressionType, SqlExpression.Constant(obj1), SqlExpression.Constant(obj2)); Assert.NotNull(exp); Assert.NotNull(exp.Left); Assert.NotNull(exp.Right); }
public void CreateQuantify(SqlExpressionType expressionType, SqlExpressionType opType) { var left = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(212))); var right = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(array))); var binary = SqlExpression.Binary(opType, left, right); var exp = SqlExpression.Quantify(expressionType, binary); Assert.Equal(expressionType, exp.ExpressionType); Assert.Equal(opType, exp.Expression.ExpressionType); }
public static void GetBinarySqlType(SqlExpressionType expressionType, object value1, object value2) { var obj1 = SqlObject.New(SqlValueUtil.FromObject(value1)); var obj2 = SqlObject.New(SqlValueUtil.FromObject(value2)); var exp = SqlExpression.Binary(expressionType, SqlExpression.Constant(obj1), SqlExpression.Constant(obj2)); var sqltType = exp.Type; var wider = obj1.Type.Wider(obj2.Type); Assert.Equal(wider, sqltType); }
public void GetQuantifyString(SqlExpressionType expressionType, SqlExpressionType opType, string expected) { var left = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(212))); var right = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(array))); var binary = SqlExpression.Binary(opType, left, right); var exp = SqlExpression.Quantify(expressionType, binary); var sql = exp.ToString(); Assert.Equal(expected, sql); }
public static void GetGroupString() { var exp = SqlExpression.Binary(SqlExpressionType.Equal, SqlExpression.Constant(SqlObject.Integer(33)), SqlExpression.Constant(SqlObject.Integer(54))); var group = SqlExpression.Group(exp); const string expected = "(33 = 54)"; var sql = group.ToString(); Assert.Equal(expected, sql); }
public static void SerializeGroup() { var exp = SqlExpression.Binary(SqlExpressionType.Equal, SqlExpression.Constant(SqlObject.Integer(33)), SqlExpression.Constant(SqlObject.Integer(54))); var group = SqlExpression.Group(exp); var result = BinarySerializeUtil.Serialize(group); Assert.NotNull(result); Assert.IsType <SqlBinaryExpression>(result.Expression); }
public static async Task ReduceGroup() { var exp = SqlExpression.Binary(SqlExpressionType.Equal, SqlExpression.Constant(SqlObject.Boolean(true)), SqlExpression.Constant(SqlObject.Boolean(false))); var group = SqlExpression.Group(exp); var reduced = await group.ReduceAsync(null); Assert.NotNull(reduced); Assert.IsType <SqlConstantExpression>(reduced); Assert.IsType <SqlObject>(((SqlConstantExpression)reduced).Value); }
public void SerializeQuantify(SqlExpressionType expressionType, SqlExpressionType opType) { var left = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(212))); var right = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(array))); var binary = SqlExpression.Binary(opType, left, right); var exp = SqlExpression.Quantify(expressionType, binary); var result = BinarySerializeUtil.Serialize(exp); Assert.IsType <SqlBinaryExpression>(result.Expression); Assert.Equal(expressionType, result.ExpressionType); Assert.Equal(opType, result.Expression.ExpressionType); }
public virtual SqlExpression VisitBinary(SqlBinaryExpression expression) { var left = expression.Left; var right = expression.Right; if (left != null) { left = Visit(left); } if (right != null) { right = Visit(right); } return(SqlExpression.Binary(expression.ExpressionType, left, right)); }
public static async void ReduceBinary(SqlExpressionType expressionType, object value1, object value2, object expected) { var obj1 = SqlObject.New(SqlValueUtil.FromObject(value1)); var obj2 = SqlObject.New(SqlValueUtil.FromObject(value2)); var exp = SqlExpression.Binary(expressionType, SqlExpression.Constant(obj1), SqlExpression.Constant(obj2)); Assert.True(exp.CanReduce); var reduced = await exp.ReduceAsync(null); Assert.NotNull(reduced); Assert.IsType <SqlConstantExpression>(reduced); var result = ((SqlConstantExpression)reduced).Value; var expectedResult = SqlObject.New(SqlValueUtil.FromObject(expected)); Assert.Equal(expectedResult, result); }
public async Task Quantify(object value, SqlExpressionType opType, SqlExpressionType expressionType, bool expected) { var left = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(SqlValueUtil.FromObject(value)))); var right = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(array))); var binary = SqlExpression.Binary(opType, left, right); var exp = SqlExpression.Quantify(expressionType, binary); var result = await exp.ReduceAsync(context); Assert.NotNull(result); Assert.Equal(SqlExpressionType.Constant, result.ExpressionType); var resultValue = ((SqlConstantExpression)result).Value; Assert.IsType <SqlBooleanType>(resultValue.Type); Assert.IsType <SqlBoolean>(resultValue.Value); Assert.Equal(expected, (bool)((SqlBoolean)resultValue.Value)); }