public void Visit(SqlCast node) { if (!node.Operand.IsNullReference()) { Visit(node.Operand); } }
public void Ctor_WithValueAndDataType_SetsValueAndDataTypeProperties() { var cast = new SqlCast(5, SqlDataType.BigInt()); Assert.Equal(5, cast.Value); Assert.Equal(SqlDataType.BigInt(), cast.DataType); }
/// <inheritdoc/> public override string Translate(SqlCompilerContext context, SqlCast node, NodeSection section) { //http://www.sqlite.org/lang_expr.html var sqlType = node.Type.Type; if (sqlType == SqlType.DateTime || sqlType == SqlType.DateTimeOffset) { switch (section) { case NodeSection.Entry: return(string.Format("STRFTIME('{0}', ", DateTimeCastFormat)); case NodeSection.Exit: return(")"); default: throw new ArgumentOutOfRangeException("section"); } } if (sqlType == SqlType.Binary || sqlType == SqlType.Char || sqlType == SqlType.Interval || sqlType == SqlType.Int16 || sqlType == SqlType.Int32 || sqlType == SqlType.Int64) { switch (section) { case NodeSection.Entry: return("CAST("); case NodeSection.Exit: return("AS " + Translate(node.Type) + ")"); default: throw new ArgumentOutOfRangeException("section"); } } if (sqlType == SqlType.Decimal || sqlType == SqlType.Double || sqlType == SqlType.Float) { switch (section) { case NodeSection.Entry: return(string.Empty); case NodeSection.Exit: return("+ 0.0"); default: throw new ArgumentOutOfRangeException("section"); } } return(string.Empty); }
public void SqlCastCloneTest() { SqlCast c = SqlDml.Cast(SqlDml.Literal(1), SqlType.Decimal, 6, 4); SqlCast cClone = (SqlCast)c.Clone(); Assert.AreNotEqual(c, cClone); Assert.AreNotEqual(c.Operand, cClone.Operand); Assert.AreEqual(c.NodeType, cClone.NodeType); Assert.AreEqual(c.Operand.NodeType, cClone.Operand.NodeType); Assert.AreEqual(c.Type, cClone.Type); }
public override string Translate(SqlCompilerContext context, SqlCast node, NodeSection section) { // casting this way behaves differently: -32768::int2 is out of range ! We need (-32768)::int2 switch (section) { case NodeSection.Entry: return("("); case NodeSection.Exit: return(")::" + Translate(node.Type)); } return(string.Empty); }
/// <inheritdoc/> public override string Translate(SqlCompilerContext context, SqlCast node, NodeSection section) { if (node.Type.Type == SqlType.DateTime) { switch (section) { case NodeSection.Entry: return("CAST("); case NodeSection.Exit: return("AS " + Translate(node.Type) + "(6))"); default: throw new ArgumentOutOfRangeException("section"); } } return(base.Translate(context, node, section)); }
public void AddTest() { SqlLiteral <int> l1 = SqlDml.Literal(1); SqlLiteral <int> l2 = SqlDml.Literal(2); SqlBinary b = l1 + l2; Assert.AreEqual(b.NodeType, SqlNodeType.Add); b = b - ~l1; Assert.AreEqual(b.NodeType, SqlNodeType.Subtract); Assert.AreEqual(b.Right.NodeType, SqlNodeType.BitNot); SqlSelect s = SqlDml.Select(); s.Columns.Add(1, "id"); b = b / s; Assert.AreEqual(b.NodeType, SqlNodeType.Divide); Assert.AreEqual(b.Right.NodeType, SqlNodeType.SubSelect); SqlCast c = SqlDml.Cast(l1, SqlType.Decimal); Assert.AreEqual(c.NodeType, SqlNodeType.Cast); SqlFunctionCall l = SqlDml.CharLength(SqlDml.Literal("name")); b = c % l; Assert.AreEqual(b.NodeType, SqlNodeType.Modulo); Assert.AreEqual(b.Right.NodeType, SqlNodeType.FunctionCall); b = l1 * (-l2); Assert.AreEqual(b.NodeType, SqlNodeType.Multiply); Assert.AreEqual(b.Right.NodeType, SqlNodeType.Negate); SqlBatch batch = SqlDml.Batch(); SqlVariable v1 = SqlDml.Variable("v1", SqlType.Double); batch.Add(v1.Declare()); batch.Add(SqlDml.Assign(v1, 1.0)); s = SqlDml.Select(); s.Columns.Add(b, "value"); batch.Add(s); }
public void SqlCastReplacingTest() { SqlCast c = SqlDml.Cast(1, SqlType.Float); SqlCast cReplacing = SqlDml.Cast(2, SqlType.Char); c.ReplaceWith(cReplacing); bool passed = false; try { c.ReplaceWith(1); } catch { passed = true; } Assert.IsTrue(passed); Assert.AreNotEqual(c, cReplacing); Assert.AreEqual(c.NodeType, cReplacing.NodeType); Assert.AreEqual(c.Operand, cReplacing.Operand); Assert.AreEqual(c.Type, cReplacing.Type); }
public override string Translate(SqlCompilerContext context, SqlCast node, NodeSection section) { var sqlType = node.Type.Type; if (sqlType == SqlType.Char || sqlType == SqlType.VarChar || sqlType == SqlType.VarCharMax) { switch (section) { case NodeSection.Entry: return("TO_CHAR("); case NodeSection.Exit: return(")"); default: throw new ArgumentOutOfRangeException("section"); } } return(base.Translate(context, node, section)); }
/// <inheritdoc/> public override string Translate(SqlCompilerContext context, SqlCast node, NodeSection section) { var sqlType = node.Type.Type; if (sqlType == SqlType.Binary || sqlType == SqlType.Char || sqlType == SqlType.Interval || sqlType == SqlType.DateTime) { switch (section) { case NodeSection.Entry: return("CAST("); case NodeSection.Exit: return("AS " + Translate(node.Type) + ")"); default: throw new ArgumentOutOfRangeException("section"); } } if (sqlType == SqlType.Int16 || sqlType == SqlType.Int32) { switch (section) { case NodeSection.Entry: return("CAST("); case NodeSection.Exit: return("AS SIGNED " + Translate(node.Type) + ")"); default: throw new ArgumentOutOfRangeException("section"); } } if (sqlType == SqlType.Decimal) { switch (section) { case NodeSection.Entry: return("CAST("); case NodeSection.Exit: return("AS " + Translate(node.Type) + ")"); default: throw new ArgumentOutOfRangeException("section"); } } if (sqlType == SqlType.Decimal || sqlType == SqlType.Double || sqlType == SqlType.Float) { switch (section) { case NodeSection.Entry: return(String.Empty); case NodeSection.Exit: return(String.Empty); default: throw new ArgumentOutOfRangeException("section"); } } return(string.Empty); }
public virtual void Visit(SqlCast node) { VisitInternal(node.Operand); }
/// <summary> /// Visits the specified <see cref="SqlCast"/>. /// </summary> /// <param name="expression"> /// The expression to visit. /// </param> public virtual void Visit(SqlCast expression) { }
public void Ctor_WithNullValue_ConvertsToNullConstant() { var cast = new SqlCast(null, SqlDataType.BigInt()); Assert.Same(SqlConstant.Null, cast.Value); }
public void ExpressionType_ReturnsCast() { var cast = new SqlCast(42, SqlDataType.Int()); Assert.Equal(SqlExpressionType.Cast, cast.ExpressionType); }