public void SqlWhileCloneTest()
        {
            SqlVariable i = SqlDml.Variable("i", SqlType.Int32);
            SqlWhile    w = SqlDml.While(i <= 1000);
            SqlBatch    b = SqlDml.Batch();

            b.Add(SqlDml.Assign(i, i + 1));
            SqlTableRef t = SqlDml.TableRef(table1);
            SqlSelect   s = SqlDml.Select(t);

            s.Columns.Add(t["Name"]);
            s.Where = t[0] == i;
            SqlIf f = SqlDml.If(SqlDml.SubQuery(s) == "Unkown", SqlDml.Break, SqlDml.Continue);

            b.Add(f);
            w.Statement = b;

            SqlWhile wClone = (SqlWhile)w.Clone();

            Assert.AreNotEqual(w, wClone);
            Assert.AreEqual(w.NodeType, wClone.NodeType);
            Assert.AreNotEqual(w.Condition, wClone.Condition);
            Assert.AreEqual(w.Condition.NodeType, wClone.Condition.NodeType);
            Assert.AreNotEqual(w.Statement, wClone.Statement);
            Assert.AreEqual(w.Statement.NodeType, wClone.Statement.NodeType);
        }
        public void SqlAssignCloneTest()
        {
            SqlParameterRef p      = SqlDml.ParameterRef("p");
            SqlAssignment   a      = SqlDml.Assign(p, 1);
            SqlAssignment   aClone = (SqlAssignment)a.Clone();

            Assert.AreNotEqual(a, aClone);
            Assert.AreEqual(a.NodeType, aClone.NodeType);
            Assert.AreNotEqual(a.Left, aClone.Left);
            Assert.AreEqual(a.Left.NodeType, aClone.Left.NodeType);
            Assert.AreNotEqual(a.Right, aClone.Right);
            Assert.AreEqual(a.Right.NodeType, aClone.Right.NodeType);
        }
        public void SqlBatchCloneTest()
        {
            SqlParameterRef p = SqlDml.ParameterRef("p");
            SqlAssignment   a = SqlDml.Assign(p, 1);
            SqlBatch        b = SqlDml.Batch();

            b.Add(a);
            b.Add(a);
            SqlBatch bClone = (SqlBatch)b.Clone();

            Assert.AreNotEqual(b, bClone);
            Assert.AreEqual(b.NodeType, bClone.NodeType);
            Assert.AreEqual(b.Count, bClone.Count);
            foreach (SqlStatement s in b)
            {
                Assert.IsFalse(bClone.Contains(s));
            }
        }
示例#4
0
        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);
        }