Exemplo n.º 1
0
        public void SqlUpdateCloneTest()
        {
            SqlTableRef t = SqlDml.TableRef(table1);
            SqlUpdate   u = SqlDml.Update(t);

            u.Values[t[0]] = 1;
            u.Values[t[1]] = "Anonym";
            u.Where        = t.Columns["ID"] == 1;
            u.Hints.Add(SqlDml.FastFirstRowsHint(10));
            SqlUpdate uClone = (SqlUpdate)u.Clone();

            Assert.AreNotEqual(u, uClone);
            Assert.AreNotEqual(u.Update, uClone.Update);
            Assert.AreEqual(u.NodeType, uClone.NodeType);
            Assert.AreEqual(u.Values.Count, uClone.Values.Count);
            foreach (KeyValuePair <ISqlLValue, SqlExpression> p in u.Values)
            {
                Assert.IsFalse(uClone.Values.ContainsKey(p.Key));
                Assert.IsFalse(uClone.Values.ContainsValue(p.Value));
            }
            if (u.Where != null)
            {
                Assert.AreNotEqual(u.Where, uClone.Where);
                Assert.AreEqual(u.Where.NodeType, uClone.Where.NodeType);
            }
            else
            {
                Assert.AreEqual(uClone.Where, null);
            }
            Assert.AreEqual(u.Hints.Count, uClone.Hints.Count);
        }
Exemplo n.º 2
0
        public void SqlInsertCloneTest()
        {
            SqlTableRef t = SqlDml.TableRef(table1);
            SqlInsert   i = SqlDml.Insert(t);

            i.Values[t[0]] = 1;
            i.Values[t[1]] = "Anonym";
            i.Hints.Add(SqlDml.FastFirstRowsHint(10));
            SqlInsert iClone = (SqlInsert)i.Clone();

            Assert.AreNotEqual(i, iClone);
            Assert.AreNotEqual(i.Into, iClone.Into);
            Assert.AreEqual(i.NodeType, iClone.NodeType);
            Assert.AreEqual(i.Values.Count, iClone.Values.Count);
            foreach (KeyValuePair <SqlColumn, SqlExpression> p in i.Values)
            {
                Assert.IsFalse(iClone.Values.ContainsKey(p.Key));
                Assert.IsFalse(iClone.Values.ContainsValue(p.Value));
            }
            Assert.AreEqual(i.Hints.Count, iClone.Hints.Count);
        }
Exemplo n.º 3
0
        public void SqlDeleteCloneTest()
        {
            SqlTableRef t = SqlDml.TableRef(table1);
            SqlDelete   d = SqlDml.Delete(t);

            d.Where = t[0] < 6;
            d.Hints.Add(SqlDml.FastFirstRowsHint(10));
            SqlDelete dClone = (SqlDelete)d.Clone();

            Assert.AreNotEqual(d, dClone);
            Assert.AreNotEqual(d.Delete, dClone.Delete);
            Assert.AreEqual(d.NodeType, dClone.NodeType);
            Assert.AreEqual(d.Hints.Count, dClone.Hints.Count);
            if (!d.Where.IsNullReference())
            {
                Assert.AreNotEqual(d.Where, dClone.Where);
                Assert.AreEqual(d.Where.NodeType, dClone.Where.NodeType);
            }
            else
            {
                Assert.AreEqual(dClone.Where, null);
            }
        }
Exemplo n.º 4
0
        public void SqlSelectCloneTest()
        {
            SqlTableRef tr1 = SqlDml.TableRef(table1);
            SqlTableRef tr2 = SqlDml.TableRef(table2);

            SqlSelect s = SqlDml.Select();

            s.Distinct = true;
            s.Limit    = 3;
            s.Columns.Add(tr1["ID"]);
            s.Columns.Add(tr1["ID"], "ID2");
            s.Columns.Add(tr1["ID"] + tr1["ID"], "SUM2");
            s.Columns.Add(tr2.Asterisk);
            s.From  = tr1.InnerJoin(tr2, tr1["ID"] == tr2["ID"]);
            s.Where = SqlDml.Like(tr1["Name"], "Marat");
            s.Hints.Add(SqlDml.FastFirstRowsHint(10));

            SqlSelect sClone = (SqlSelect)s.Clone();

            Assert.AreNotEqual(s, sClone);
            Assert.AreNotEqual(s.Columns, sClone.Columns);
            for (int i = 0, l = s.Columns.Count; i < l; i++)
            {
                Assert.AreNotEqual(s.Columns[i], sClone.Columns[i]);
            }
            for (int i = 0, l = s.GroupBy.Count; i < l; i++)
            {
                Assert.AreNotEqual(s.Columns[i], sClone.Columns[i]);
            }
            Assert.AreEqual(s.Distinct, sClone.Distinct);
            if (s.From == null)
            {
                Assert.AreEqual(s.From, sClone.From);
            }
            else
            {
                Assert.AreNotEqual(s.From, sClone.From);
                Assert.AreEqual(s.From.NodeType, sClone.From.NodeType);
            }
            if (!s.Having.IsNullReference())
            {
                Assert.AreNotEqual(s.Having, sClone.Having);
                Assert.AreEqual(s.Having.NodeType, sClone.Having.NodeType);
            }

            Assert.AreEqual(s.NodeType, sClone.NodeType);
            Assert.IsFalse(s.OrderBy == sClone.OrderBy);
            Assert.AreEqual(s.OrderBy.Count, sClone.OrderBy.Count);
            for (int i = 0, l = s.OrderBy.Count; i < l; i++)
            {
                Assert.AreNotEqual(s.OrderBy[i], sClone.OrderBy[i]);
                Assert.AreEqual(s.OrderBy[i].Ascending, sClone.OrderBy[i].Ascending);
                Assert.AreNotEqual(s.OrderBy[i].Expression, sClone.OrderBy[i].Expression);
                Assert.AreEqual(s.OrderBy[i].Position, sClone.OrderBy[i].Position);
            }

            Assert.AreEqual(s.Limit, sClone.Limit);
            if (s.Where != null)
            {
                Assert.AreNotEqual(s.Where, sClone.Where);
                Assert.AreEqual(s.Where.NodeType, sClone.Where.NodeType);
            }

            s.Where &= tr1[0] > 1200 || tr2[1] != "Marat";
            s.OrderBy.Add(tr1["ID"], false);
            s.OrderBy.Add(2);

            sClone = (SqlSelect)s.Clone();

            Assert.AreNotEqual(s, sClone);
            Assert.AreNotEqual(s.Columns, sClone.Columns);
            for (int i = 0, l = s.Columns.Count; i < l; i++)
            {
                Assert.AreNotEqual(s.Columns[i], sClone.Columns[i]);
            }
            for (int i = 0, l = s.GroupBy.Count; i < l; i++)
            {
                Assert.AreNotEqual(s.Columns[i], sClone.Columns[i]);
            }
            Assert.AreEqual(s.Distinct, sClone.Distinct);
            if (s.From == null)
            {
                Assert.AreEqual(s.From, sClone.From);
            }
            else
            {
                Assert.AreNotEqual(s.From, sClone.From);
                Assert.AreEqual(s.From.NodeType, sClone.From.NodeType);
            }
            if (s.Having != null)
            {
                Assert.AreNotEqual(s.Having, sClone.Having);
                Assert.AreEqual(s.Having.NodeType, sClone.Having.NodeType);
            }

            Assert.AreEqual(s.NodeType, sClone.NodeType);
            Assert.AreNotEqual(s.OrderBy, sClone.OrderBy);
            Assert.AreEqual(s.OrderBy.Count, sClone.OrderBy.Count);
            for (int i = 0, l = s.OrderBy.Count; i < l; i++)
            {
                Assert.AreNotEqual(s.OrderBy[i], sClone.OrderBy[i]);
                Assert.AreEqual(s.OrderBy[i].Ascending, sClone.OrderBy[i].Ascending);
                if (s.OrderBy[i].Expression.IsNullReference())
                {
                    Assert.AreEqual(s.OrderBy[i].Expression, sClone.OrderBy[i].Expression);
                }
                else
                {
                    Assert.AreNotEqual(s.OrderBy[i].Expression, sClone.OrderBy[i].Expression);
                }
                Assert.AreEqual(s.OrderBy[i].Position, sClone.OrderBy[i].Position);
            }

            Assert.AreEqual(s.Limit, sClone.Limit);
            if (s.Where != null)
            {
                Assert.AreNotEqual(s.Where, sClone.Where);
                Assert.AreEqual(s.Where.NodeType, sClone.Where.NodeType);
            }
            Assert.AreEqual(s.Hints.Count, sClone.Hints.Count);

            SqlSelect   s2 = SqlDml.Select();
            SqlQueryRef t  = SqlDml.QueryRef(s, "SUBSELECT");

            s2.From = t;
            s2.Columns.Add(t.Asterisk);
            SqlSelect s2Clone = (SqlSelect)s2.Clone();

            Assert.AreNotEqual(s2, s2Clone);
            Assert.AreEqual(s2.Columns.Count, s2Clone.Columns.Count);
        }