public override SqlExpression VisitConstantNumeric(PlSqlParser.ConstantNumericContext context) { var value = context.numeric().GetText(); var formatInfo = new NumberFormatInfo { NumberDecimalSeparator = "." }; var number = SqlNumber.Parse(value, formatInfo); SqlObject obj; if (number.CanBeInt32) { obj = SqlObject.Integer((int)number); } else if (number.CanBeInt64) { obj = SqlObject.BigInt((long)number); } else { obj = SqlObject.Numeric(number); } return(SqlExpression.Constant(obj)); }
public void CastStringToNumber() { var exp = SqlExpression.Cast(SqlExpression.Constant(DataObject.String("12.3e4")), PrimitiveTypes.Numeric()); SqlExpression casted = null; Assert.DoesNotThrow(() => casted = exp.Evaluate()); Assert.IsNotNull(casted); Assert.IsInstanceOf <SqlConstantExpression>(casted); var value = ((SqlConstantExpression)casted).Value; Assert.IsNotNull(value.Value); Assert.IsInstanceOf <NumericType>(value.Type); Assert.AreEqual(SqlTypeCode.Numeric, value.Type.TypeCode); Assert.AreEqual(SqlNumber.Parse("12.3e4"), value.Value); }
public override ISqlObject CreateFrom(object value) { if (value == null) { return(SqlNumber.Null); } if (value is SqlNumber) { return((SqlNumber)value); } if (value is byte) { return(new SqlNumber((byte)value)); } if (value is short) { return(new SqlNumber((short)value)); } if (value is int) { return(new SqlNumber((int)value)); } if (value is long) { return(new SqlNumber((long)value)); } if (value is float) { return(new SqlNumber((float)value, GetPrecision())); } if (value is double) { return(new SqlNumber((double)value, GetPrecision())); } if (value is byte[]) { return(new SqlNumber((byte[])value, Scale, GetPrecision())); } if (value is string) { return(SqlNumber.Parse((string)value)); } throw new NotSupportedException("The value passed is not supported"); }