use of io.shardingjdbc.core.parsing.parser.context.limit.LimitValue in project sharding-jdbc by shardingjdbc.
the class SQLRewriteEngineTest method assertRewriteForLimitForMemoryGroupBy.
@Test
public void assertRewriteForLimitForMemoryGroupBy() {
selectStatement.setLimit(new Limit(DatabaseType.MySQL));
selectStatement.getLimit().setOffset(new LimitValue(2, -1, true));
selectStatement.getLimit().setRowCount(new LimitValue(2, -1, false));
selectStatement.getOrderByItems().add(new OrderItem("x", "id", OrderDirection.ASC, OrderDirection.ASC, Optional.<String>absent()));
selectStatement.getGroupByItems().add(new OrderItem("x", "id", OrderDirection.DESC, OrderDirection.ASC, Optional.<String>absent()));
selectStatement.getSqlTokens().add(new TableToken(17, "table_x"));
selectStatement.getSqlTokens().add(new OffsetToken(33, 2));
selectStatement.getSqlTokens().add(new RowCountToken(36, 2));
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule, "SELECT x.id FROM table_x x LIMIT 2, 2", DatabaseType.MySQL, selectStatement);
assertThat(rewriteEngine.rewrite(true).toSQL(tableTokens, null), is("SELECT x.id FROM table_1 x LIMIT 0, 2147483647"));
}
use of io.shardingjdbc.core.parsing.parser.context.limit.LimitValue in project sharding-jdbc by shardingjdbc.
the class SQLRewriteEngineTest method assertRewriteForRowNumForNotRewriteLimit.
@Test
public void assertRewriteForRowNumForNotRewriteLimit() {
selectStatement.setLimit(new Limit(DatabaseType.Oracle));
selectStatement.getLimit().setOffset(new LimitValue(2, -1, true));
selectStatement.getLimit().setRowCount(new LimitValue(4, -1, false));
selectStatement.getSqlTokens().add(new TableToken(68, "table_x"));
selectStatement.getSqlTokens().add(new OffsetToken(119, 2));
selectStatement.getSqlTokens().add(new RowCountToken(98, 4));
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule, "SELECT * FROM (SELECT row_.*, rownum rownum_ FROM (SELECT x.id FROM table_x x) row_ WHERE rownum<=4) t WHERE t.rownum_>2", DatabaseType.Oracle, selectStatement);
assertThat(rewriteEngine.rewrite(false).toSQL(tableTokens, null), is("SELECT * FROM (SELECT row_.*, rownum rownum_ FROM (SELECT x.id FROM table_1 x) row_ WHERE rownum<=4) t WHERE t.rownum_>2"));
}
use of io.shardingjdbc.core.parsing.parser.context.limit.LimitValue in project sharding-jdbc by shardingjdbc.
the class LimitDecoratorMergedResultTest method assertNextWithRowCount.
@Test
public void assertNextWithRowCount() throws SQLException {
Limit limit = new Limit(DatabaseType.MySQL);
limit.setOffset(new LimitValue(2, -1, true));
limit.setRowCount(new LimitValue(2, -1, false));
selectStatement.setLimit(limit);
mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
MergedResult actual = mergeEngine.merge();
assertTrue(actual.next());
assertTrue(actual.next());
assertFalse(actual.next());
}
use of io.shardingjdbc.core.parsing.parser.context.limit.LimitValue in project sharding-jdbc by shardingjdbc.
the class LimitDecoratorMergedResultTest method assertNextForSkipAll.
@Test
public void assertNextForSkipAll() throws SQLException {
Limit limit = new Limit(DatabaseType.MySQL);
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.LimitValue in project sharding-jdbc by shardingjdbc.
the class RowNumberDecoratorMergedResultTest method assertNextForSkipAll.
@Test
public void assertNextForSkipAll() throws SQLException {
Limit limit = new Limit(DatabaseType.Oracle);
limit.setOffset(new LimitValue(Integer.MAX_VALUE, -1, true));
selectStatement.setLimit(limit);
mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
MergedResult actual = mergeEngine.merge();
assertFalse(actual.next());
}
Aggregations