Skip to content

Commit ff70a94

Browse files
committed
string separator
1 parent ea1a11b commit ff70a94

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/NHibernate/Criterion/InExpression.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private SqlString GetSqlString(ICriteriaQuery criteriaQuery, SqlString[] columns
7979
if (columns.Length <= 1 || criteriaQuery.Factory.Dialect.SupportsRowValueConstructorSyntaxInInList)
8080
{
8181
var wrapInParens = columns.Length > 1;
82-
SqlString comaSeparator = new SqlString(", ");
82+
const string comaSeparator = ", ";
8383
var singleValueParam = SqlStringHelper.Repeat(new SqlString(bogusParam), columns.Length, comaSeparator, wrapInParens);
8484

8585
var parameters = SqlStringHelper.Repeat(singleValueParam, Values.Length, comaSeparator, wrapInParens: false);
@@ -99,8 +99,10 @@ private SqlString GetSqlString(ICriteriaQuery criteriaQuery, SqlString[] columns
9999
var cols = new SqlString(
100100
" ( ",
101101
SqlStringHelper.Join(new SqlString(" = ", bogusParam, " and "), columns),
102-
new SqlString("= ", bogusParam, " ) "));
103-
cols = SqlStringHelper.Repeat(cols, Values.Length, new SqlString(" or "), wrapInParens: Values.Length > 1);
102+
"= ",
103+
bogusParam,
104+
" ) ");
105+
cols = SqlStringHelper.Repeat(cols, Values.Length, " or ", wrapInParens: Values.Length > 1);
104106
return cols;
105107
}
106108

src/NHibernate/SqlCommand/SqlStringHelper.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ public static SqlString Join(SqlString separator, IEnumerable objects)
3131
return buf.ToSqlString();
3232
}
3333

34+
internal static SqlString Join(string separator, IList<SqlString> strings)
35+
{
36+
if (strings.Count == 0)
37+
return SqlString.Empty;
38+
39+
if (strings.Count == 1)
40+
return strings[0];
41+
42+
var buf = new SqlStringBuilder();
43+
44+
buf.Add(strings[0]);
45+
for (var index = 1; index < strings.Count; index++)
46+
{
47+
buf.Add(separator).Add(strings[index]);
48+
}
49+
50+
return buf.ToSqlString();
51+
}
3452

3553
public static SqlString[] Add(SqlString[] x, string sep, SqlString[] y)
3654
{
@@ -91,7 +109,7 @@ internal static SqlString ParametersList(List<Parameter> parameters)
91109
return builder.ToSqlString();
92110
}
93111

94-
internal static SqlString Repeat(SqlString placeholder, int count, SqlString separator, bool wrapInParens)
112+
internal static SqlString Repeat(SqlString placeholder, int count, string separator, bool wrapInParens)
95113
{
96114
if (count == 0)
97115
return SqlString.Empty;
@@ -101,7 +119,7 @@ internal static SqlString Repeat(SqlString placeholder, int count, SqlString sep
101119
? new SqlString("(", placeholder, ")")
102120
: placeholder;
103121

104-
var builder = new SqlStringBuilder((placeholder.Count + separator.Count) * count + 1);
122+
var builder = new SqlStringBuilder((placeholder.Count + 1) * count + 1);
105123

106124
if (wrapInParens)
107125
{

0 commit comments

Comments
 (0)