Skip to content

Commit 4813b40

Browse files
committed
Minimize changes
1 parent ea81bc5 commit 4813b40

File tree

3 files changed

+10
-33
lines changed

3 files changed

+10
-33
lines changed

src/NHibernate/Hql/Ast/ANTLR/Tree/CaseNode.cs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,17 @@ public override IType DataType
2929
if (ExpectedType != null)
3030
return ExpectedType;
3131

32-
if (base.DataType != null)
33-
return base.DataType;
34-
35-
var dataType = GetTypeFromResultNodes();
36-
37-
foreach (var node in GetResultNodes().OfType<ISelectExpression>())
32+
foreach (var node in GetResultNodes())
3833
{
39-
if (node.DataType == null && node is IExpectedTypeAwareNode typeAwareNode)
40-
{
41-
typeAwareNode.ExpectedType = dataType;
42-
}
34+
if (node is ISelectExpression select && !(node is ParameterNode))
35+
return select.DataType;
4336
}
4437

45-
base.DataType = dataType;
46-
return dataType;
38+
throw new HibernateException("Unable to determine data type of CASE statement.");
4739
}
4840
set { base.DataType = value; }
4941
}
5042

51-
private IType GetTypeFromResultNodes()
52-
{
53-
foreach (var node in GetResultNodes())
54-
{
55-
if (node is ISelectExpression select && select.DataType != null)
56-
{
57-
return select.DataType;
58-
}
59-
}
60-
61-
throw new HibernateException("Unable to determine data type of CASE statement.");
62-
}
63-
6443
public IEnumerable<IASTNode> GetResultNodes()
6544
{
6645
for (int i = 0; i < ChildCount; i++)

src/NHibernate/Linq/Functions/StringGenerator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject,
217217
{
218218
var expression = visitor.Visit(targetObject).AsExpression();
219219
var index = treeBuilder.Add(visitor.Visit(arguments[0]).AsExpression(), treeBuilder.Constant(1));
220-
221-
return treeBuilder.TransparentCast(treeBuilder.MethodCall("substring", expression, index, treeBuilder.Constant(1)), typeof(char));
220+
return treeBuilder.MethodCall("substring", expression, index, treeBuilder.Constant(1));
222221
}
223222
}
224223

src/NHibernate/Linq/Visitors/ParameterTypeLocator.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ internal static void SetParameterTypes(
9393
continue;
9494
}
9595

96-
namedParameter.Type = GetParameterType(sessionFactory, constantExpressions, visitor, namedParameter, out var isGuessedType);
97-
namedParameter.IsGuessedType = isGuessedType;
96+
namedParameter.Type = GetParameterType(sessionFactory, constantExpressions, visitor, namedParameter, out var tryProcessInHql);
97+
namedParameter.IsGuessedType = tryProcessInHql;
9898
}
9999
}
100100

@@ -147,9 +147,9 @@ private static IType GetParameterType(
147147
HashSet<ConstantExpression> constantExpressions,
148148
ConstantTypeLocatorVisitor visitor,
149149
NamedParameter namedParameter,
150-
out bool isGuessedType)
150+
out bool tryProcessInHql)
151151
{
152-
isGuessedType = false;
152+
tryProcessInHql = false;
153153
// All constant expressions have the same type/value
154154
var constantExpression = constantExpressions.First();
155155
var constantType = constantExpression.Type.UnwrapIfNullable();
@@ -161,8 +161,7 @@ private static IType GetParameterType(
161161

162162
// Leave hql logic to determine the type except when the value is a char. Hql logic detects a char as a string, which causes an exception
163163
// when trying to set a string db parameter with a char value.
164-
isGuessedType = !(constantExpression.Value is char);
165-
164+
tryProcessInHql = !(constantExpression.Value is char);
166165
// No related MemberExpressions was found, guess the type by value or its type when null.
167166
// When a numeric parameter is compared to different columns with different types (e.g. Where(o => o.Single >= singleParam || o.Double <= singleParam))
168167
// do not change the parameter type, but instead cast the parameter when comparing with different column types.

0 commit comments

Comments
 (0)