-
Notifications
You must be signed in to change notification settings - Fork 933
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
Fix Linq .Second bug for PostgreSQL et al. #3528
base: master
Are you sure you want to change the base?
Conversation
@@ -33,8 +34,13 @@ public DateTimePropertiesHqlGenerator() | |||
|
|||
public override HqlTreeNode BuildHql(MemberInfo member, Expression expression, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) | |||
{ | |||
return treeBuilder.MethodCall(member.Name.ToLowerInvariant(), | |||
var functionName = member.Name.ToLowerInvariant(); | |||
if (functionName == "second" && (visitor.SessionFactory as ISessionFactoryImplementor)?.Dialect.Functions.ContainsKey("secondtruncated") == true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we instead of checking if the function is supported define secondtruncated
in the base dialect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love to, but the only meaningful way to do that, I think, would be to create a new kind of ISQLFunction, which aliases another function.
RegisterFunction("secondtruncated ", new SQLFunctionAlias(this, "second"));
Mysql seems to be failing because it needs to use |
436ff1d
to
0ba96aa
Compare
Refactor tests
The problem isn't flooring, but rather the old MySQL version used on the TC build. |
Co-authored-by: Frédéric Delaporte <[email protected]>
Co-authored-by: Frédéric Delaporte <[email protected]>
Fix for #3525
The actual fix was adding a new HQL function "secondtruncated", which is used if it is available, otherwise it falls back to the old "second". Another option would be to fix the "second" function in the dialects where it doesn't work, but that could be considered a more breaking change. As mentioned in the issue, Hibernate has defined "second" to actually include fractional seconds, and have adjusted the dialects where the corresponding SQL function truncates.
The most changes were in DateTimeTests.cs. I really wanted to use that test class since it already tests exactly this (but not seconds), but to get fractional seconds into the Northwind dataset was a bit icky, so I opted to create specific test data.
I used the approach of comparing the result from the LINQ query with the result from the same query run in memory. Of course that doesn't work in scenarios with null, case sensitivity etc., but here it works just fine.
The MySQL test fails on Github, for some reason. I can't make it fail locally.