Skip to content

Commit 053467c

Browse files
authored
Fix paging in DB2Dialect (#2547)
* Also mark TextHolder as not supported by DB2Dialect
1 parent 70d5358 commit 053467c

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/NHibernate.Test/DialectTest/DB2DialectFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void GetLimitString()
2626

2727
SqlString limited = dialect.GetLimitString(sql, new SqlString("111"), new SqlString("222"));
2828
Assert.AreEqual(
29-
"select * from (select rownumber() over(order by a, x) as rownum, a, b, c from d where X = ? and Z = ? order by a, x) as tempresult where rownum between 111+1 and 222",
29+
"select a,b,c from (select rownumber() over(order by a, x) as rownum, a, b, c from d where X = ? and Z = ? order by a, x) as tempresult where rownum between 111+1 and 222",
3030
limited.ToString());
3131
Assert.AreEqual(2, limited.GetParameterCount());
3232
}
@@ -58,4 +58,4 @@ public void GetLimitString_NoOffsetSpecified_UsesFetchFirstOnly()
5858
Assert.AreEqual(2, limited.GetParameterCount());
5959
}
6060
}
61-
}
61+
}

src/NHibernate.Test/ReadOnly/TextHolder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class TextHolder
1010
/// </summary>
1111
public static bool SupportedForDialect(Dialect.Dialect dialect)
1212
{
13-
return !(dialect is FirebirdDialect || dialect is Oracle8iDialect || dialect is MsSqlCeDialect || dialect is HanaRowStoreDialect);
13+
return !(dialect is FirebirdDialect || dialect is Oracle8iDialect || dialect is MsSqlCeDialect || dialect is HanaRowStoreDialect || dialect is DB2Dialect);
1414
}
1515

1616
private long id;

src/NHibernate/Dialect/DB2Dialect.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,28 +232,29 @@ public override bool SupportsVariableLimit
232232
get { return false; }
233233
}
234234

235-
public override SqlString GetLimitString(SqlString querySqlString, SqlString offset, SqlString limit)
235+
public override SqlString GetLimitString(SqlString sql, SqlString offset, SqlString limit)
236236
{
237237
if (offset == null)
238238
{
239-
return new SqlString(querySqlString,
240-
" fetch first ",
241-
limit,
242-
" rows only");
239+
return new SqlString(sql, " fetch first ", limit, " rows only");
243240
}
244241

242+
ExtractColumnOrAliasNames(sql, out var selectColumns, out _, out _);
243+
245244
/*
246245
* "select * from (select row_number() over(orderby_clause) as rownum, "
247246
* querySqlString_without select
248247
* " ) as tempresult where rownum between ? and ?"
249248
*/
250-
string rownumClause = GetRowNumber(querySqlString);
249+
string rownumClause = GetRowNumber(sql);
251250

252251
SqlStringBuilder pagingBuilder = new SqlStringBuilder();
253252
pagingBuilder
254-
.Add("select * from (select ")
253+
.Add("select " )
254+
.Add(string.Join(",", selectColumns))
255+
.Add(" from (select ")
255256
.Add(rownumClause)
256-
.Add(querySqlString.Substring(7))
257+
.Add(sql.Substring(7))
257258
.Add(") as tempresult where rownum ");
258259

259260
if (limit != null)

0 commit comments

Comments
 (0)