示例#1
0
        public void IsEmptyTest()
        {
            var builder = new Builder(this.ctx);

            Assert.True(builder.IsEmpty);
            Assert.Equal(0, builder.Sql.Length);
        }
示例#2
0
        public void HashTest()
        {
            var builder1 = new Builder(this.ctx);
            builder1.SELECT("*").FROM("Foo").WHERE("Id", 1);

            var builder2 = new Builder(this.ctx);
            builder2.SELECT("*").FROM("Foo").WHERE("Id", 1);

            Assert.Equal(builder1.Hash, builder2.Hash);
        }
示例#3
0
        public void ParametersTest()
        {
            var builder = new Builder(this.ctx);

            builder.SELECT("*").FROM("Foo").WHERE("Id", 1);

            Assert.Equal(3, builder.Parameters.Count);
            Assert.Equal("["+this.ctx.DatabaseName+"].[dbo].[Foo]", ((SqlTable)builder.Parameters["@p0p"]).Value);
            Assert.Equal("[Id]", ((SqlId)builder.Parameters["@p1p"]).Value);
            Assert.Equal(1, builder.Parameters["@p2p"]);
        }
示例#4
0
 public Builder WITH(string alias, Builder subQuery)
 {
     return this.WITH(new SqlId(alias), subQuery);
 }
示例#5
0
 public Builder WITH(SqlId alias, Builder subQuery)
 {
     return this.WITH("{0} AS ({1})", alias, subQuery);
 }
示例#6
0
        public Builder UPDATE(Builder subQuery)
        {
            var withAlias = new SqlId("subQuery");

            return this.WITH(withAlias, subQuery).UPDATE(withAlias);
        }
示例#7
0
 public Builder FROM(Builder subQuery)
 {
     return this.FROM(new SqlId(Guid.NewGuid().ToString()), subQuery);
 }
示例#8
0
        public Builder FROM(string alias, Builder subQuery)
        {
            if (alias.Contains('{') && alias.Contains('}'))
            {
                return this.FROM(alias, new object[] { subQuery });
            }

            return this.FROM(new SqlId(alias), subQuery);
        }
示例#9
0
 public Builder FROM(SqlId alias, Builder subQuery)
 {
     return this.FROM("({0}) {1}", subQuery, alias);
 }
示例#10
0
        public Builder DELETE_FROM(Builder subQuery)
        {
            var withAlias = new SqlId("subQuery");

            return this.WITH(withAlias, subQuery).DELETE_FROM(withAlias);
        }
示例#11
0
        public void SqlTest()
        {
            var builder = new Builder(this.ctx);

            builder.SELECT("*").FROM("Foo").WHERE("Bar = 'Hello'");

            var expected = new StringBuilder();
            expected.AppendLine("SELECT * ");
            expected.AppendLine("FROM @p0p ");
            expected.Append("WHERE Bar = 'Hello' ");

            Assert.Equal(expected.ToString(), builder.Sql);
        }
示例#12
0
        public void _Test()
        {
            var builder = new Builder(this.ctx);

            builder
                .SELECT("Foo")
                ._("Bar")
                .FROM("Baz")
                .WHERE("Abc = '123'")
                ._("Xyz = '987'")
            ;

            var expected = new StringBuilder();
            expected.AppendLine("SELECT Foo , Bar ");
            expected.AppendLine("FROM @p0p ");
            expected.Append("WHERE Abc = '123' AND Xyz = '987' ");

            Assert.Equal(expected.ToString(), builder.Sql);
        }
示例#13
0
        public void _IFTest()
        {
            var builder = new Builder(this.ctx);

            var abc = true;
            var xyz = false;

            builder
                .SELECT("*")
                .FROM("Baz")
                .WHERE()
                ._IF(abc, "Abc = '123'")
                ._IF(xyz, "Xyz = '987'")
            ;

            var expected = new StringBuilder();
            expected.AppendLine("SELECT * ");
            expected.AppendLine("FROM @p0p ");
            expected.Append("WHERE Abc = '123' ");

            Assert.Equal(expected.ToString(), builder.Sql);
        }
示例#14
0
        public void WITHTest()
        {
            var builder = new Builder(this.ctx);

            builder.WITH("Bar AS (SELECT * FROM Foo)");

            Assert.Equal("WITH Bar AS (SELECT * FROM Foo) ", builder.Sql);

            builder.WITH("Baz",  new Builder(this.ctx).SELECT("*").FROM("Bar"));

            var expected = new StringBuilder();
            expected.AppendLine("WITH Bar AS (SELECT * FROM Foo) , @p0p AS (SELECT * ");
            expected.Append("FROM @p1p ) ");

            Assert.Equal(expected.ToString(), builder.Sql);
        }