Skip to content

Commit 3c62b9c

Browse files
committed
Fix NH-2840 - SetFirstResult and SetMaxResults do not work correctly on Oracle (ODP.NET)
Fixes the following tests on Oracle: NHibernate.Test.Criteria.CriteriaQueryTest.SimplePagination NHibernate.Test.Criteria.Lambda.IntegrationFixture.RowCount NHibernate.Test.Legacy.FooBarTest.Limit NHibernate.Test.Legacy.FooBarTest.PSCache NHibernate.Test.Legacy.SQLFunctionsTest.SQLFunctions NHibernate.Test.NHSpecificTest.NH1533.Fixture.Can_query_using_two_orderby_and_limit_altogether NHibernate.Test.NHSpecificTest.NH2251.Fixture.FuturePagedHql NHibernate.Test.NHSpecificTest.NH2251.Fixture.HqlWithOffsetAndLimit NHibernate.Test.NHSpecificTest.NH2251.Fixture.MultiplePagingParametersInSingleQuery NHibernate.Test.Pagination.PaginationFixture.PagTest NHibernate.Test.QueryTest.DetachedQueryFixture.ExecutableQuery
1 parent 34fdd91 commit 3c62b9c

File tree

1 file changed

+86
-86
lines changed

1 file changed

+86
-86
lines changed
Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,87 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Data;
4-
using System.Linq;
5-
using NHibernate.Engine;
6-
using NHibernate.SqlCommand;
7-
using NHibernate.Type;
8-
9-
namespace NHibernate.Param
10-
{
11-
/// <summary>
12-
/// Autogenerated parameter for <see cref="IQuery.SetMaxResults"/>.
13-
/// </summary>
14-
public class QueryTakeParameterSpecification : IParameterSpecification
15-
{
16-
// NOTE: don't use this for HQL take clause
17-
private readonly string[] idTrack;
18-
private readonly string limitParametersNameForThisQuery = "<nhtake" + Guid.NewGuid().ToString("N"); // NH_note: to avoid conflicts using MultiQuery/Future
19-
private readonly IType type = NHibernateUtil.Int32;
20-
21-
public QueryTakeParameterSpecification()
22-
{
23-
idTrack = new[] { limitParametersNameForThisQuery };
24-
}
25-
26-
#region IParameterSpecification Members
27-
28-
public void Bind(IDbCommand command, IList<Parameter> sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session)
29-
{
30-
Bind(command, sqlQueryParametersList, 0, sqlQueryParametersList, queryParameters, session);
31-
}
32-
33-
public void Bind(IDbCommand command, IList<Parameter> multiSqlQueryParametersList, int singleSqlParametersOffset, IList<Parameter> sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session)
34-
{
35-
// The QueryTakeParameterSpecification is unique so we can use multiSqlQueryParametersList
36-
var effectiveParameterLocations = multiSqlQueryParametersList.GetEffectiveParameterLocations(limitParametersNameForThisQuery).ToArray();
37-
if (effectiveParameterLocations.Any())
38-
{
39-
// if the dialect does not support variable limits the parameter may was removed
40-
int value = queryParameters.RowSelection.MaxRows;
41-
int position = effectiveParameterLocations.Single();
42-
type.NullSafeSet(command, value, position, session);
43-
}
44-
}
45-
46-
public IType ExpectedType
47-
{
48-
get { return type; }
49-
set { throw new InvalidOperationException(); }
50-
}
51-
52-
public string RenderDisplayInfo()
53-
{
54-
return "query-take";
55-
}
56-
57-
public IEnumerable<string> GetIdsForBackTrack(IMapping sessionFactory)
58-
{
59-
return idTrack;
60-
}
61-
62-
#endregion
63-
64-
public override bool Equals(object obj)
65-
{
66-
return Equals(obj as QueryTakeParameterSpecification);
67-
}
68-
69-
public bool Equals(QueryTakeParameterSpecification other)
70-
{
71-
if (ReferenceEquals(null, other))
72-
{
73-
return false;
74-
}
75-
if (ReferenceEquals(this, other))
76-
{
77-
return true;
78-
}
79-
return Equals(other.limitParametersNameForThisQuery, limitParametersNameForThisQuery);
80-
}
81-
82-
public override int GetHashCode()
83-
{
84-
return limitParametersNameForThisQuery.GetHashCode();
85-
}
86-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Linq;
5+
using NHibernate.Engine;
6+
using NHibernate.SqlCommand;
7+
using NHibernate.Type;
8+
9+
namespace NHibernate.Param
10+
{
11+
/// <summary>
12+
/// Autogenerated parameter for <see cref="IQuery.SetMaxResults"/>.
13+
/// </summary>
14+
public class QueryTakeParameterSpecification : IParameterSpecification
15+
{
16+
// NOTE: don't use this for HQL take clause
17+
private readonly string[] idTrack;
18+
private readonly string limitParametersNameForThisQuery = "<nhtake" + Guid.NewGuid().ToString("N"); // NH_note: to avoid conflicts using MultiQuery/Future
19+
private readonly IType type = NHibernateUtil.Int32;
20+
21+
public QueryTakeParameterSpecification()
22+
{
23+
idTrack = new[] { limitParametersNameForThisQuery };
24+
}
25+
26+
#region IParameterSpecification Members
27+
28+
public void Bind(IDbCommand command, IList<Parameter> sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session)
29+
{
30+
Bind(command, sqlQueryParametersList, 0, sqlQueryParametersList, queryParameters, session);
31+
}
32+
33+
public void Bind(IDbCommand command, IList<Parameter> multiSqlQueryParametersList, int singleSqlParametersOffset, IList<Parameter> sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session)
34+
{
35+
// The QueryTakeParameterSpecification is unique so we can use multiSqlQueryParametersList
36+
var effectiveParameterLocations = multiSqlQueryParametersList.GetEffectiveParameterLocations(limitParametersNameForThisQuery).ToArray();
37+
if (effectiveParameterLocations.Any())
38+
{
39+
// if the dialect does not support variable limits the parameter may was removed
40+
int value = Loader.Loader.GetLimitUsingDialect(queryParameters.RowSelection, session.Factory.Dialect) ?? queryParameters.RowSelection.MaxRows;
41+
int position = effectiveParameterLocations.Single();
42+
type.NullSafeSet(command, value, position, session);
43+
}
44+
}
45+
46+
public IType ExpectedType
47+
{
48+
get { return type; }
49+
set { throw new InvalidOperationException(); }
50+
}
51+
52+
public string RenderDisplayInfo()
53+
{
54+
return "query-take";
55+
}
56+
57+
public IEnumerable<string> GetIdsForBackTrack(IMapping sessionFactory)
58+
{
59+
return idTrack;
60+
}
61+
62+
#endregion
63+
64+
public override bool Equals(object obj)
65+
{
66+
return Equals(obj as QueryTakeParameterSpecification);
67+
}
68+
69+
public bool Equals(QueryTakeParameterSpecification other)
70+
{
71+
if (ReferenceEquals(null, other))
72+
{
73+
return false;
74+
}
75+
if (ReferenceEquals(this, other))
76+
{
77+
return true;
78+
}
79+
return Equals(other.limitParametersNameForThisQuery, limitParametersNameForThisQuery);
80+
}
81+
82+
public override int GetHashCode()
83+
{
84+
return limitParametersNameForThisQuery.GetHashCode();
85+
}
86+
}
8787
}

0 commit comments

Comments
 (0)