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 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 static void NewCast(object value, SqlTypeCode destTypeCode, int p, int s) { var targetType = PrimitiveTypes.Type(destTypeCode, new { precision = p, scale = s, maxSize = p, size = p }); var obj = SqlObject.New(SqlValueUtil.FromObject(value)); var exp = SqlExpression.Constant(obj); var cast = SqlExpression.Cast(exp, targetType); Assert.NotNull(cast.Value); Assert.NotNull(cast.TargetType); }
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 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 void CreateVarAssign(string name, object value) { var obj = SqlObject.New(SqlValueUtil.FromObject(value)); var exp = SqlExpression.Constant(obj); var varRef = SqlExpression.VariableAssign(name, exp); Assert.NotNull(varRef.Value); Assert.Equal(exp, varRef.Value); Assert.Equal(name, varRef.VariableName); }
public static void CreateStringMatch(SqlExpressionType expressionType, string value, string pattern) { var exp = SqlExpression.StringMatch(expressionType, SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value))), SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(pattern))), null); Assert.NotNull(exp); Assert.Equal(expressionType, exp.ExpressionType); Assert.NotNull(exp.Left); Assert.NotNull(exp.Pattern); }
public static void GetStringMatchString(SqlExpressionType expressionType, string value, string pattern, string expected) { var exp = SqlExpression.StringMatch(expressionType, SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value))), SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(pattern))), null); var sql = exp.ToString(); Assert.Equal(expected, sql); }
public static void MultiValueKeyEqualToNull(object value1, object value2) { var key1 = new IndexKey(new[] { SqlObject.New(SqlValueUtil.FromObject(value1)), SqlObject.New(SqlValueUtil.FromObject(value2)) }); var key2 = key1.NullKey; Assert.NotEqual(key1, key2); Assert.True(key2.IsNull); }
public static void GetReferenceAssignString(string name, object value, string expected) { var objName = ObjectName.Parse(name); var obj = SqlObject.New(SqlValueUtil.FromObject(value)); var exp = SqlExpression.Constant(obj); var refAssign = SqlExpression.ReferenceAssign(objName, exp); var sql = refAssign.ToString(); Assert.Equal(expected, sql); }
public async Task NonCorrelatedSelect(string column, SqlExpressionType op, SqlExpressionType subOp, object value1, object value2, long expected) { var columnName = new ObjectName(left.TableInfo.TableName, column); var exp1 = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value1))); var exp2 = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value2))); var array = SqlExpression.Constant(SqlObject.Array(new SqlArray(new[] { exp1, exp2 }))); var result = await left.SelectNonCorrelatedAsync(null, columnName, op, subOp, array); Assert.NotNull(result); Assert.Equal(expected, result.RowCount); }
private static SqlExpression FormDefaultValue(object value) { if (value == null) { return(null); } var obj = SqlObject.New(SqlValueUtil.FromObject(value)); return(SqlExpression.Constant(obj)); }
public static void GetCastString(object value, SqlTypeCode destTypeCode, int p, int s, string expected) { var targetType = PrimitiveTypes.Type(destTypeCode, new { precision = p, scale = s, maxSize = p, size = p }); var obj = SqlObject.New(SqlValueUtil.FromObject(value)); var exp = SqlExpression.Constant(obj); var cast = SqlExpression.Cast(exp, targetType); var sql = cast.ToString(); Assert.Equal(expected, sql); }
public static void SerializeCast(object value, SqlTypeCode destTypeCode, int p, int s) { var targetType = PrimitiveTypes.Type(destTypeCode, new { precision = p, scale = s, maxSize = p, size = p }); var obj = SqlObject.New(SqlValueUtil.FromObject(value)); var exp = SqlExpression.Constant(obj); var cast = SqlExpression.Cast(exp, targetType); var result = BinarySerializeUtil.Serialize(cast); Assert.IsType <SqlConstantExpression>(result.Value); }
public static void GetConditionString(bool test, object ifTrue, object ifFalse, string expected) { var testExp = SqlExpression.Constant(SqlObject.Boolean(test)); var ifTrueExp = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(ifTrue))); var ifFalseExp = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(ifFalse))); var condition = SqlExpression.Condition(testExp, ifTrueExp, ifFalseExp); var sql = condition.ToString(); Assert.Equal(expected, sql); }
public static void SerializeReferenceAssign(string name, object value) { var objName = ObjectName.Parse(name); var obj = SqlObject.New(SqlValueUtil.FromObject(value)); var exp = SqlExpression.Constant(obj); var refAssign = SqlExpression.ReferenceAssign(objName, exp); var result = BinarySerializeUtil.Serialize(refAssign); Assert.Equal(objName, result.ReferenceName); Assert.IsType <SqlConstantExpression>(result.Value); }
public static void CreateInvokeWithMixedArguments(string methodName, string argName1, object value1, object value2) { var name = ObjectName.Parse(methodName); var arg1 = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value1))); var arg2 = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value2))); var invoke = new Invoke(name); invoke.Arguments.Add(new InvokeArgument(argName1, arg1)); Assert.Throws <ArgumentException>(() => invoke.Arguments.Add(new InvokeArgument(arg2))); }
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 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 static void CastTo(SqlTypeCode srcTypeCode, bool value, SqlTypeCode destTypeCode, int p, int s, object expected) { var b = (SqlBoolean)value; var srcType = PrimitiveTypes.Boolean(srcTypeCode); var destType = PrimitiveTypes.Type(destTypeCode, new { precision = p, scale = s, maxSize = p }); Assert.True(srcType.CanCastTo(b, destType)); var result = srcType.Cast(b, destType); var expectedValue = SqlValueUtil.FromObject(expected); Assert.Equal(expectedValue, result); }
public static void CompareMultipleValue(object value1a, object value1b, object value2a, object value2b, int expetced) { var key1 = new IndexKey(new[] { SqlObject.New(SqlValueUtil.FromObject(value1a)), SqlObject.New(SqlValueUtil.FromObject(value1b)) }); var key2 = new IndexKey(new[] { SqlObject.New(SqlValueUtil.FromObject(value2a)), SqlObject.New(SqlValueUtil.FromObject(value2b)) }); Assert.Equal(expetced, key1.CompareTo(key2)); }
public static void CreateReferenceAssign(string name, object value) { var objName = ObjectName.Parse(name); var obj = SqlObject.New(SqlValueUtil.FromObject(value)); var exp = SqlExpression.Constant(obj); var refAssign = SqlExpression.ReferenceAssign(objName, exp); Assert.NotNull(refAssign.ReferenceName); Assert.NotNull(refAssign.Value); Assert.Equal(objName, refAssign.ReferenceName); }
public static void MultiValueKeyEqual(object value1a, object value1b, object value2a, object value2b, bool expected) { var key1 = new IndexKey(new [] { SqlObject.New(SqlValueUtil.FromObject(value1a)), SqlObject.New(SqlValueUtil.FromObject(value1b)) }); var key2 = new IndexKey(new[] { SqlObject.New(SqlValueUtil.FromObject(value2a)), SqlObject.New(SqlValueUtil.FromObject(value2b)) }); Assert.Equal(expected, key1.Equals(key2)); }
public static void SerializeCondition(bool test, object ifTrue, object ifFalse) { var testExp = SqlExpression.Constant(SqlObject.Boolean(test)); var ifTrueExp = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(ifTrue))); var ifFalseExp = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(ifFalse))); var condition = SqlExpression.Condition(testExp, ifTrueExp, ifFalseExp); var result = BinarySerializeUtil.Serialize(condition); Assert.NotNull(result.Test); Assert.NotNull(result.IfTrue); Assert.NotNull(result.IfFalse); }
public static void CastToString(string value, SqlTypeCode destTypeCode, int size, string expexted) { var dts = SqlDayToSecond.Parse(value); var type = new SqlDayToSecondType(); var destType = PrimitiveTypes.Type(destTypeCode, new { size }); var result = type.Cast(dts, destType); var exp = SqlValueUtil.FromObject(expexted); Assert.NotNull(result); Assert.Equal(exp, result); }
public static async void ReduceConstant(object value) { var obj = SqlObject.New(SqlValueUtil.FromObject(value)); var exp = SqlExpression.Constant(obj); Assert.False(exp.CanReduce); Assert.NotNull(exp.Value); var reduced = await exp.ReduceAsync(null); Assert.IsType <SqlConstantExpression>(reduced); Assert.Equal(obj, ((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 async Task ReduceVarAssign(string name, object value) { var obj = SqlObject.New(SqlValueUtil.FromObject(value)); var exp = SqlExpression.Constant(obj); var varRef = SqlExpression.VariableAssign(name, exp); Assert.True(varRef.CanReduce); var result = await varRef.ReduceAsync(context); Assert.NotNull(result); Assert.IsType <SqlConstantExpression>(result); }
public static async Task ReduceCondition(bool test, object ifTrue, object ifFalse, object expected) { var testExp = SqlExpression.Constant(SqlObject.Boolean(test)); var ifTrueExp = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(ifTrue))); var ifFalseExp = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(ifFalse))); var condition = SqlExpression.Condition(testExp, ifTrueExp, ifFalseExp); var result = await condition.ReduceAsync(null); Assert.IsType <SqlConstantExpression>(result); var expectedValue = SqlObject.New(SqlValueUtil.FromObject(expected)); Assert.Equal(expectedValue, ((SqlConstantExpression)result).Value); }
public static void CreateInvokeWithNamedArguments(string methodName, string argName1, object value1, string argName2, object value2) { var name = ObjectName.Parse(methodName); var arg1 = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value1))); var arg2 = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value2))); var invoke = new Invoke(name); invoke.Arguments.Add(new InvokeArgument(argName1, arg1)); invoke.Arguments.Add(new InvokeArgument(argName2, arg2)); Assert.Equal(name, invoke.MethodName); Assert.Equal(2, invoke.Arguments.Count); Assert.True(invoke.IsNamed); Assert.True(invoke.Arguments[0].IsNamed); Assert.True(invoke.Arguments[1].IsNamed); }