Skip to content

Commit 9bf8ceb

Browse files
committed
Merge branch 'aochsner-NH-3525'
2 parents d476c4c + 0bce49f commit 9bf8ceb

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

src/NHibernate.Test/DialectTest/DB2DialectFixture.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,38 @@ public void GetLimitString()
2424
" order by a, x"
2525
});
2626

27-
SqlString limited = dialect.GetLimitString(sql, new SqlString("111"), new SqlString("222"));
27+
SqlString limited = dialect.GetLimitString(sql, new SqlString("111"), new SqlString("222"));
2828
Assert.AreEqual(
2929
"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",
3030
limited.ToString());
3131
Assert.AreEqual(2, limited.GetParameterCount());
3232
}
33+
34+
[Test]
35+
public void GetLimitString_NoOffsetSpecified_UsesFetchFirstOnly()
36+
{
37+
// arrange
38+
DB2Dialect dialect = new DB2Dialect();
39+
SqlString sql = new SqlString(
40+
new object[]
41+
{
42+
"select a, b, c ",
43+
"from d",
44+
" where X = ",
45+
Parameter.Placeholder,
46+
" and Z = ",
47+
Parameter.Placeholder,
48+
" order by a, x"
49+
});
50+
51+
// act
52+
SqlString limited = dialect.GetLimitString(sql, null, new SqlString("222"));
53+
54+
// assert
55+
Assert.AreEqual(
56+
"select a, b, c from d where X = ? and Z = ? order by a, x fetch first 222 rows only",
57+
limited.ToString());
58+
Assert.AreEqual(2, limited.GetParameterCount());
59+
}
3360
}
3461
}

src/NHibernate/Dialect/DB2Dialect.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,22 @@ public override bool UseMaxForLimit
208208
get { return true; }
209209
}
210210

211+
/// <summary></summary>
212+
public override bool SupportsVariableLimit
213+
{
214+
get { return false; }
215+
}
216+
211217
public override SqlString GetLimitString(SqlString querySqlString, SqlString offset, SqlString limit)
212218
{
219+
if (offset == null)
220+
{
221+
return new SqlString(querySqlString,
222+
" fetch first ",
223+
limit,
224+
" rows only");
225+
}
226+
213227
/*
214228
* "select * from (select row_number() over(orderby_clause) as rownum, "
215229
* querySqlString_without select
@@ -224,20 +238,14 @@ public override SqlString GetLimitString(SqlString querySqlString, SqlString off
224238
.Add(querySqlString.Substring(7))
225239
.Add(") as tempresult where rownum ");
226240

227-
if (offset != null && limit != null)
241+
if (limit != null)
228242
{
229243
pagingBuilder
230244
.Add("between ")
231245
.Add(offset)
232246
.Add("+1 and ")
233247
.Add(limit);
234248
}
235-
else if (limit != null)
236-
{
237-
pagingBuilder
238-
.Add("<= ")
239-
.Add(limit);
240-
}
241249
else
242250
{
243251
// We just have an offset.

0 commit comments

Comments
 (0)