Skip to content

Commit

Permalink
fix #33 Limit support
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoht committed Jul 12, 2016
1 parent c97a233 commit 9a6866e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

package com.dangdang.ddframe.rdb.integrate.db.statement;

import java.sql.SQLException;

import com.dangdang.ddframe.rdb.integrate.db.AbstractShardingDataBasesOnlyDBUnitTest;
import com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource;
import org.dbunit.DatabaseUnitException;
import org.junit.Before;
import org.junit.Test;

import java.sql.SQLException;

public final class ShardingDataBasesOnlyForStatementWithSelectTest extends AbstractShardingDataBasesOnlyDBUnitTest {

private ShardingDataSource shardingDataSource;
Expand Down Expand Up @@ -65,6 +65,14 @@ public void assertSelectLimitWithBindingTable() throws SQLException, DatabaseUni
assertDataSet("integrate/dataset/Empty.xml", shardingDataSource.getConnection(), "t_order_item", String.format(sql, 10, 19, 1000, 1909, 10000, 2));
}

@Test
public void assertSelectLimitOffsetWithBindingTable() throws SQLException, DatabaseUnitException {
String sql = "SELECT i.* FROM `t_order` o JOIN `t_order_item` i ON o.user_id = i.user_id AND o.order_id = i.order_id"
+ " WHERE o.`user_id` IN (%s, %s) AND o.`order_id` BETWEEN %s AND %s ORDER BY i.item_id DESC LIMIT %s OFFSET %s";
assertDataSet("integrate/dataset/db/expect/select/SelectLimitWithBindingTable.xml", shardingDataSource.getConnection(), "t_order_item", String.format(sql, 10, 19, 1000, 1909, 2, 2));
assertDataSet("integrate/dataset/Empty.xml", shardingDataSource.getConnection(), "t_order_item", String.format(sql, 10, 19, 1000, 1909, 2, 10000));
}

@Test
public void assertSelectGroupByWithBindingTable() throws SQLException, DatabaseUnitException {
String sql = "SELECT count(*) as items_count, o.`user_id` FROM `t_order` o JOIN `t_order_item` i ON o.user_id = i.user_id AND o.order_id = i.order_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@
</condition-contexts>
<limit offset="0" row-count="5" />
</assert>

<assert id="assertSelectForLimitOffset" sql="SELECT * FROM order o LIMIT 5 OFFSET 4" expected-sql="SELECT * FROM [Token(order)] o LIMIT 0, 9">
<tables>
<table name="order" alias="o" />
</tables>
<condition-contexts>
<condition-context />
</condition-contexts>
<limit offset="4" row-count="5" />
</assert>
</asserts>
1 change: 1 addition & 0 deletions sharding-jdbc-doc/content/post/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ weight = 1

1. [ISSUE #36](https://github.com/dangdangdotcom/sharding-jdbc/issues/36) ShardingPreparedStatement无法反复设置参数
1. [ISSUE #114](https://github.com/dangdangdotcom/sharding-jdbc/issues/114) ShardingPreparedStatement执行批处理任务时,反复解析sql导致oom
1. [ISSUE #33](https://github.com/dangdangdotcom/sharding-jdbc/issues/33) Limit支持问题

## 1.3.1

Expand Down

0 comments on commit 9a6866e

Please sign in to comment.