jmenziessmith / sqlmodeller Goto Github PK
View Code? Open in Web Editor NEWSql Statement Builder
License: MIT License
Sql Statement Builder
License: MIT License
Is support for UNION and UNION ALL planned?
How can I build this join (simplified, taken from a more complex query):
FROM eqReq.LineItemMaster lim
INNER JOIN (
eqReq.Compendium cp INNER JOIN eqReq.CompendiumEntry ce ON cp.Id = ce.CompendiumId
) ON lim.CompendiumId = cp.Id
The join inside the parentheses has priority, and this can make a difference to the query result.
See http://www.bennadel.com/blog/1059-grouping-join-clauses-in-sql.htm
First, let me say this is the most promising SQL builder for .NET I have seen so far!
It seems to have the right amount of support for programmatically creating SQL statements while still giving the developer control over the output.
Here is my issue:
I would like to add the following class and extensions, but the library does not make it easy to extend it, as the class is not picked up by the query compiler and no new IColumnSelectorCompiler can be registered.
public class PlainColumnSelector: SqlColumnSelector, IColumnSelector
{
public PlainColumnSelector(Table table, string fieldName) : base(FullName(table.Alias, fieldName)) { }
static string FullName(string tableAlias, string fieldName) {
if (string.IsNullOrWhiteSpace(tableAlias)) {
return fieldName;
}
return string.Format("{0}.{1}", tableAlias, fieldName);
}
}
public static class Extensions
{
public static SelectQuery Select(this SelectQuery query, Table table, string field) {
query.SelectColumns.Add(new PlainColumnSelector(table, field));
return query;
}
}
Does not seem to be directly supported. Is there a workaround?
Test case should return ...IN ('Jorge' ,'Benito' ,'Juan' ), but returns IN (Jorge ,Benito ,Juan )
public void WhereColumnIn() {
var teamTable = new Table("t", "Team");
var names = new List<string> { "Jorge", "Benito", "Juan" };
var select = new SelectQuery()
.From(teamTable)
.Select(teamTable, "Name", "T_NAME")
.WhereColumnIn(teamTable.Alias, "Name", names, DbType.AnsiString);
var query = new Query();
query.SelectQuery = select;
var compiled = query.Compile(false); // NOTE: useParameters = false
Console.WriteLine(compiled.Sql);
}
This could break code that uses parameter literals as values, but the following change would fix the test case:
public class NoQueryParameterManager : IQueryParameterManager
{
public string Parameterize(string value, DbType type, string alias = null)
{
// return value;
return ToStringHelper.ValueString(value, type);
}
}
Now, with this fix applied, if one passes a string that one does not want to quote, as in @name, then one would have to use a DbType other than string or DateTime, probably best: DbType.Object, as in:
public void WhereColumnValue() {
var teamTable = new Table("t", "Team");
var select = new SelectQuery()
.From(teamTable)
.Select(teamTable, "Name", "T_NAME")
.WhereColumnValue(teamTable.Alias, "Name", Compare.Equal, "Jorge")
.WhereColumnValue(teamTable.Alias, "Name", Compare.Equal, "@Name", DbType.Object);
var query = new Query();
query.SelectQuery = select;
var compiled = query.Compile(false);
Console.WriteLine(compiled.Sql);
}
Karl
Not really an issue, but:
I needed to use SqlModeller in a netstandard based project running in VS 2017 and converted the solution over to the new project model. You may have a look at the netstandard1.2 branch of my fork: https://github.com/kwaclaw/SqlModeller . (Note: I did not change the version number).
Among the changes made:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.