Skip to content

Commit 9c058af

Browse files
committed
NH-2038 - Fix SqlStringHelper.RemoveAsAliasesFromSql method when alias is not present on a string
1 parent 0465dc4 commit 9c058af

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/NHibernate.Test/NHSpecificTest/NH2318/Fixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void CriteriaTrimFunctionsWithParameters()
5656
"trim",
5757
NHibernateUtil.String,
5858
Projections.Constant("f"),
59-
Projections.SqlProjection("from as literal", null, null), // Silly hack to get "from" as a second argument.
59+
Projections.SqlProjection("from", null, null), // Silly hack to get "from" as a second argument.
6060
Projections.Property("Name")),
6161
"irst"));
6262
IList<A> items = criteria.List<A>();

src/NHibernate/SqlCommand/SqlStringHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public static SqlString[] Add(SqlString[] x, string sep, SqlString[] y)
4444

4545
public static SqlString RemoveAsAliasesFromSql(SqlString sql)
4646
{
47-
return sql.Substring(0, sql.LastIndexOfCaseInsensitive(" as "));
47+
int index = sql.LastIndexOfCaseInsensitive(" as ");
48+
if (index < 0) return sql;
49+
return sql.Substring(0, index);
4850
}
4951

5052

0 commit comments

Comments
 (0)