mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-27 14:30:16 +00:00
HHH-12369 Fix for integer overflow in limit handler when using Integer.MAX_VALUE for maxResults on DB2
This commit is contained in:
parent
5aaabb0f03
commit
58af371440
@ -169,6 +169,13 @@ protected final int bindLimitParameters(RowSelection selection, PreparedStatemen
|
||||
protected final int getMaxOrLimit(RowSelection selection) {
|
||||
final int firstRow = convertToFirstRowValue( LimitHelper.getFirstRow( selection ) );
|
||||
final int lastRow = selection.getMaxRows();
|
||||
return useMaxForLimit() ? lastRow + firstRow : lastRow;
|
||||
final int maxRows = useMaxForLimit() ? lastRow + firstRow : lastRow;
|
||||
// Use Integer.MAX_VALUE on overflow
|
||||
if ( maxRows < 0 ) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
else {
|
||||
return maxRows;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,14 @@ public int bindLimitParametersAtEndOfQuery(RowSelection selection, PreparedState
|
||||
@Override
|
||||
public void setMaxRows(RowSelection selection, PreparedStatement statement) throws SQLException {
|
||||
if ( LimitHelper.hasMaxRows( selection ) ) {
|
||||
statement.setMaxRows( selection.getMaxRows() + convertToFirstRowValue( LimitHelper.getFirstRow( selection ) ) );
|
||||
int maxRows = selection.getMaxRows() + convertToFirstRowValue( LimitHelper.getFirstRow( selection ) );
|
||||
// Use Integer.MAX_VALUE on overflow
|
||||
if ( maxRows < 0 ) {
|
||||
statement.setMaxRows( Integer.MAX_VALUE );
|
||||
}
|
||||
else {
|
||||
statement.setMaxRows( maxRows );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user