Skip to content

Commit 8b2f45a

Browse files
committed
NHibernate.Test.Legacy.FumTest.CompositeIDQuery: corrected parameter positions for positional parameters (not working with Oracle)
SVN: trunk@5169
1 parent db4b6d3 commit 8b2f45a

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/NHibernate/Engine/QueryParameters.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@ public QueryParameters(IType[] positionalParameterTypes, object[] positionalPara
105105
_collectionKeys = collectionKeys;
106106
_readOnly = readOnly;
107107
_resultTransformer = transformer;
108-
109-
if (_positionalParameterLocations == null)
110-
{
111-
CreatePositionalParameterLocations();
112-
}
113108
}
114109

115110
public QueryParameters(IType[] positionalParameterTypes, object[] positionalParameterValues,
@@ -196,15 +191,15 @@ public IDictionary<string, LockMode> LockModes
196191
set { _lockModes = value; }
197192
}
198193

199-
private void CreatePositionalParameterLocations()
194+
private void CreatePositionalParameterLocations(ISessionFactoryImplementor factory)
200195
{
201-
if (_positionalParameterTypes != null)
196+
_positionalParameterLocations = new int[_positionalParameterTypes.Length];
197+
int location = 0;
198+
for (int i = 0; i < _positionalParameterLocations.Length; i++)
202199
{
203-
_positionalParameterLocations = new int[_positionalParameterTypes.Length];
204-
for (int i = 0; i < _positionalParameterLocations.Length; i++)
205-
{
206-
_positionalParameterLocations[i] = i;
207-
}
200+
var span = _positionalParameterTypes[i].GetColumnSpan(factory);
201+
_positionalParameterLocations[i] = location;
202+
location += span;
208203
}
209204
}
210205

@@ -460,6 +455,8 @@ public SqlType[] PrepareParameterTypes(SqlString sqlString, ISessionFactoryImple
460455
int parameterIndex = 0;
461456
int totalSpan = 0;
462457

458+
CreatePositionalParameterLocations(factory);
459+
463460
IList<Parameter> sqlParameters = FindParametersIn(sqlString);
464461

465462
for (int index = 0; index < PositionalParameterTypes.Length; index++)
@@ -470,7 +467,7 @@ public SqlType[] PrepareParameterTypes(SqlString sqlString, ISessionFactoryImple
470467
int location = PositionalParameterLocations[index];
471468
location = FindAdjustedParameterLocation(location);
472469
int span = type.GetColumnSpan(factory);
473-
SetParameterLocation(sqlParameters, startParameterIndex + parameterIndex, location, span);
470+
SetParameterLocation(sqlParameters, startParameterIndex + totalSpan, location, span);
474471

475472
totalSpan += span;
476473
parameterIndex++;
@@ -483,7 +480,7 @@ public SqlType[] PrepareParameterTypes(SqlString sqlString, ISessionFactoryImple
483480

484481
int location = FilteredParameterLocations[index];
485482
int span = type.GetColumnSpan(factory);
486-
SetParameterLocation(sqlParameters, startParameterIndex + parameterIndex, location, span);
483+
SetParameterLocation(sqlParameters, startParameterIndex + totalSpan, location, span);
487484

488485
totalSpan += span;
489486
parameterIndex++;
@@ -510,7 +507,7 @@ public SqlType[] PrepareParameterTypes(SqlString sqlString, ISessionFactoryImple
510507
while ((location < sqlParameters.Count) && (sqlParameters[location].ParameterPosition != null))
511508
location++;
512509

513-
SetParameterLocation(sqlParameters, startParameterIndex + parameterIndex, location, span);
510+
SetParameterLocation(sqlParameters, startParameterIndex + totalSpan, location, span);
514511
}
515512

516513
totalSpan += span;

0 commit comments

Comments
 (0)