public void IsEmptyTest() { var builder = new Builder(this.ctx); Assert.True(builder.IsEmpty); Assert.Equal(0, builder.Sql.Length); }
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); }
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"]); }
public Builder WITH(string alias, Builder subQuery) { return this.WITH(new SqlId(alias), subQuery); }
public Builder WITH(SqlId alias, Builder subQuery) { return this.WITH("{0} AS ({1})", alias, subQuery); }
public Builder UPDATE(Builder subQuery) { var withAlias = new SqlId("subQuery"); return this.WITH(withAlias, subQuery).UPDATE(withAlias); }
public Builder FROM(Builder subQuery) { return this.FROM(new SqlId(Guid.NewGuid().ToString()), subQuery); }
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); }
public Builder FROM(SqlId alias, Builder subQuery) { return this.FROM("({0}) {1}", subQuery, alias); }
public Builder DELETE_FROM(Builder subQuery) { var withAlias = new SqlId("subQuery"); return this.WITH(withAlias, subQuery).DELETE_FROM(withAlias); }
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); }
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); }
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); }
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); }