Skip to content

Commit

Permalink
Merge pull request sqlkata#541 from mnsrulz/master
Browse files Browse the repository at this point in the history
allow select without table to support cross apply
  • Loading branch information
ahmad-moussawi authored Mar 4, 2022
2 parents a1f8e3f + 666e112 commit 9554778
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
19 changes: 19 additions & 0 deletions QueryBuilder.Tests/SelectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -814,5 +814,24 @@ public void EscapeClauseThrowsForMultipleCharacters()
.HavingContains("Column1", @"TestString\%", false, @"\aa");
});
}


[Fact]
public void BasicSelectRaw_WithNoTable()
{
var q = new Query().SelectRaw("somefunction() as c1");

var c = Compilers.CompileFor(EngineCodes.SqlServer, q);
Assert.Equal("SELECT somefunction() as c1", c.ToString());
}

[Fact]
public void BasicSelect_WithNoTable()
{
var q = new Query().Select("c1");
var c = Compilers.CompileFor(EngineCodes.SqlServer, q);
Assert.Equal("SELECT [c1]", c.ToString());
}

}
}
10 changes: 5 additions & 5 deletions QueryBuilder/Compilers/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,14 @@ public virtual string CompileTableExpression(SqlResult ctx, AbstractFrom from)

public virtual string CompileFrom(SqlResult ctx)
{
if (!ctx.Query.HasComponent("from", EngineCode))
if (ctx.Query.HasComponent("from", EngineCode))
{
throw new InvalidOperationException("No table is set");
}
var from = ctx.Query.GetOneComponent<AbstractFrom>("from", EngineCode);

var from = ctx.Query.GetOneComponent<AbstractFrom>("from", EngineCode);
return "FROM " + CompileTableExpression(ctx, from);
}

return "FROM " + CompileTableExpression(ctx, from);
return string.Empty;
}

public virtual string CompileJoins(SqlResult ctx)
Expand Down

0 comments on commit 9554778

Please sign in to comment.