-
-
Notifications
You must be signed in to change notification settings - Fork 518
Include the Engine when cloning a FromClause #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Before I launch into this long comment, I wanted to say how much I appreciate this library, and I'm sure there are considerations here that I'm missing. Running some further tests has led me to other issues. var query = new Query("Foo")
.ForSqlServer(q => q.From("Bar"));I would expect this to give me a table name of public Q ClearComponent(string component, string engineCode = null)
{
if (engineCode == null)
{
engineCode = EngineScope;
}
Clauses = Clauses
.Where(x => !(x.Component == component && (engineCode == null || x.Engine == null || engineCode == x.Engine)))
.ToList();
return (Q)this;
}I agree that if It's a little complicated because I think that There's a similar issue in I get that this is complex because Actually, each query can only have one var query = new Query("Foo")
.Limit(5)
.ForSqlServer(q => q.Limit(10));That's a lot from what I thought was a small issue. I'm interested to hear what you think. |
|
I'll add that both Edit: Hmm, no, I think I can work around |
|
@asherber thanks for this great analysis, so I can conclude that we have the following issues here:
Is there something that I've missed? |
|
While Here's my current suggestion for public C GetOneComponent<C>(string component, string engineCode = null) where C : AbstractClause
{
engineCode = engineCode ?? EngineScope;
var all = GetComponents<C>(component, engineCode);
return all.FirstOrDefault(c => c.Engine == engineCode) ?? all.FirstOrDefault();
}I think In addition, here's what I would suggest for public Q From(string table)
{
var newClause = new FromClause
{
Table = table,
};
return AddOrReplaceComponent("from", newClause);
}
public Q AddOrReplaceComponent(string component, AbstractClause clause, string engineCode = null)
{
engineCode = engineCode ?? EngineScope;
var current = GetComponents(component).SingleOrDefault(c => c.Engine == engineCode);
if (current != null)
Clauses.Remove(current);
return AddComponent(component, clause, engineCode);
} |
|
I can work all of this into this PR, if you agree. |
|
@asherber you are right, agree from my side. |
|
Okay, thanks. I'm a little swamped this weekend, will probably look at this early next week. |
GetOneComponent prioritizes engine
|
@ahmad-moussawi I think this is almost complete now. There's one thing which troubles me a little that has to do with var query = new Query("mytable")
.Limit(5)
.Offset(10)
.ForMySql(q => q.Limit(20));In the above example, I first set a generic limit and offset, and then I specify that MySql should have a different offset. As part of that code, the generic offset gets copied into the MySql var query = new Query("mytable")
.Limit(5)
.Offset(10)
.ForMySql(q => q.Limit(20))
.Offset(50);Here the generic offset of 10 gets copied into the MySql One could argue that this is a poorly formed query -- that the user shouldn't have provided two offsets. But I can see a case where a base query is set up, as in the first example, and then later in the code the generic offset is changed based on some other condition. Should the library handle this better? If so, then we'll need to stop copying the generic offset into the (The generic What do you think? |
|
Hmm, not sure I can solve for this last case without one of these more drastic steps:
The problem is that a value of 0 could mean "look at the generic", or it could have been explicitly set. |
|
@asherber You are totally right, this scenario can happen when using it dynamically, I think separating the limit and offset to two components is the best scenario here. if you like, open another issue for it, so we can track it alone, and I will merge this PR for now. |
|
Thanks, will do. |
|
@ahmad-moussawi I've got the work on |
|
@asherber yes sure 😃 |
|
Merged with master now, Thanks! |
Fixes #239
Turns out I was right the first time, even though my fork was out of date. If the
Engineisn't preserved duringFromClause.Clone(), then 2 of the 3 unit tests I added fail.