-
Notifications
You must be signed in to change notification settings - Fork 934
Proper support for IN clause for composite values in Criteria #2158
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
2abfeb9
to
f5495f3
Compare
@bahusoid I think you do not gain much from substituting "bogus" parameters because you have more string manipulations. I think it would be clearer (and probably more efficient) to split this code into 3 branches:
|
I'm not trying to gain anything. I need to split SQL template generation and parameters generation. This This |
I need to use functions like @hazzik So please clarify how suggested splitting allows me to effectively generate SQL without Current splitting (the same as in hibernate):
Suggested by you additional splitting really won't change much. |
I don't understand what's wrong with putting actual parameters into the query. I've got following snippet: /// the beginning of the method is skipped
var parametersList = GetParameterTypedValues(criteria, criteriaQuery)
.Select(tv => criteriaQuery.NewQueryParameter(tv).ToArray())
.ToList();
return GetSqlString(criteriaQuery, columns, parametersList);
}
private static SqlString GetSqlString(
ICriteriaQuery criteriaQuery,
SqlString[] columns,
List<Parameter[]> parametersList)
{
if (columns.Length == 1)
{
//single column: col1 in (?, ?)
return new SqlString(
columns[0],
" in (",
SqlStringHelper.Join(", ", parametersList.Select(p => p.Single())),
")"
);
}
if (criteriaQuery.Factory.Dialect.SupportsRowValueConstructorSyntaxInInList)
{
//multi column: (col1, col2) in ((?, ?), (?, ?))
return new SqlString(
"(",
SqlStringHelper.Join(", ", columns),
") in ((",
SqlStringHelper.Join("), (", parametersList.Select(p => SqlStringHelper.Join(", ", p))),
"))"
);
}
//((col1 = ? and col2 = ?) or (col1 = ? and col2 = ?))
var objects = parametersList.Select(
parameters => new SqlString(
"(",
SqlStringHelper.Join(
" and ", columns.Zip(parameters, (c, p) => new SqlString(c, " = ", p))),
")"));
return new SqlString(
"(",
SqlStringHelper.Join(" or ", objects),
")"
);
} First two can be collapsed together, but I didn't like it. |
|
Yes, I did not run tests. It has come from wrong-ish assumption on how |
53f74a8
to
ff70a94
Compare
Co-Authored-By: Frédéric Delaporte <12201973+fredericDelaporte@users.noreply.github.com>
I was reluctant to approve it because there were code changes which I think could be improved. I tried to do that, but never got time to finish. |
Ported latest version of hibernate InExpression. As NHibernate version generates completely incorrect SQL for composite keys.