use of io.shardingjdbc.core.parsing.parser.context.limit.Limit in project sharding-jdbc by shardingjdbc.
the class TopAndRowNumberDecoratorMergedResultTest method assertNextWithOffsetWithoutRowCount.
@Test
public void assertNextWithOffsetWithoutRowCount() throws SQLException {
Limit limit = new Limit(DatabaseType.SQLServer);
limit.setOffset(new LimitValue(2, -1, true));
selectStatement.setLimit(limit);
mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
MergedResult actual = mergeEngine.merge();
for (int i = 0; i < 7; i++) {
assertTrue(actual.next());
}
assertFalse(actual.next());
}
use of io.shardingjdbc.core.parsing.parser.context.limit.Limit in project sharding-jdbc by shardingjdbc.
the class TopAndRowNumberDecoratorMergedResultTest method assertNextForSkipAll.
@Test
public void assertNextForSkipAll() throws SQLException {
Limit limit = new Limit(DatabaseType.SQLServer);
limit.setOffset(new LimitValue(Integer.MAX_VALUE, -1, true));
selectStatement.setLimit(limit);
mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
MergedResult actual = mergeEngine.merge();
assertFalse(actual.next());
}
use of io.shardingjdbc.core.parsing.parser.context.limit.Limit in project sharding-jdbc by shardingjdbc.
the class SQLRewriteEngine method appendLimitRowCount.
private void appendLimitRowCount(final SQLBuilder sqlBuilder, final RowCountToken rowCountToken, final int count, final List<SQLToken> sqlTokens, final boolean isRewrite) {
SelectStatement selectStatement = (SelectStatement) sqlStatement;
Limit limit = selectStatement.getLimit();
if (!isRewrite) {
sqlBuilder.appendLiterals(String.valueOf(rowCountToken.getRowCount()));
} else if ((!selectStatement.getGroupByItems().isEmpty() || !selectStatement.getAggregationSelectItems().isEmpty()) && !selectStatement.isSameGroupByAndOrderByItems()) {
sqlBuilder.appendLiterals(String.valueOf(Integer.MAX_VALUE));
} else {
sqlBuilder.appendLiterals(String.valueOf(limit.isNeedRewriteRowCount() ? rowCountToken.getRowCount() + limit.getOffsetValue() : rowCountToken.getRowCount()));
}
int beginPosition = rowCountToken.getBeginPosition() + String.valueOf(rowCountToken.getRowCount()).length();
appendRest(sqlBuilder, count, sqlTokens, beginPosition);
}
use of io.shardingjdbc.core.parsing.parser.context.limit.Limit in project sharding-jdbc by shardingjdbc.
the class DQLMergeEngineTest method assertBuildIteratorStreamMergedResultWithSQLServerLimit.
@Test
public void assertBuildIteratorStreamMergedResultWithSQLServerLimit() throws SQLException {
selectStatement.setLimit(new Limit(DatabaseType.SQLServer));
mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
MergedResult actual = mergeEngine.merge();
assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class));
assertThat(((TopAndRowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(IteratorStreamMergedResult.class));
}
use of io.shardingjdbc.core.parsing.parser.context.limit.Limit in project sharding-jdbc by shardingjdbc.
the class DQLMergeEngineTest method assertBuildIteratorStreamMergedResultWithMySQLLimit.
@Test
public void assertBuildIteratorStreamMergedResultWithMySQLLimit() throws SQLException {
selectStatement.setLimit(new Limit(DatabaseType.MySQL));
mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
MergedResult actual = mergeEngine.merge();
assertThat(actual, instanceOf(LimitDecoratorMergedResult.class));
assertThat(((LimitDecoratorMergedResult) actual).getMergedResult(), instanceOf(IteratorStreamMergedResult.class));
}
Aggregations