mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add PagerUtils
This commit is contained in:
@@ -30,7 +30,17 @@ public class PagerUtilsTest0 extends TestCase {
|
||||
"FROM t", result);
|
||||
}
|
||||
|
||||
public void test_mysql_3() throws Exception {
|
||||
public void test_mysql_group_0() throws Exception {
|
||||
String sql = "select type, count(*) from t group by type";
|
||||
String result = PagerUtils.count(sql, JdbcConstants.MYSQL);
|
||||
Assert.assertEquals("SELECT COUNT(*)" + //
|
||||
"\nFROM (SELECT type, COUNT(*)" + //
|
||||
"\n\tFROM t" + //
|
||||
"\n\tGROUP BY type" + //
|
||||
"\n\t)", result);
|
||||
}
|
||||
|
||||
public void test_mysql_union_0() throws Exception {
|
||||
String sql = "select id, name from t1 union select id, name from t2 order by id";
|
||||
String result = PagerUtils.count(sql, JdbcConstants.MYSQL);
|
||||
Assert.assertEquals("SELECT COUNT(*)\n" + //
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package PagerUtils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.PagerUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class PagerUtilsTestLimit_0 extends TestCase {
|
||||
|
||||
public void test_mysql_0() throws Exception {
|
||||
String sql = "select * from t";
|
||||
String result = PagerUtils.limit(sql, JdbcConstants.MYSQL, 0, 10);
|
||||
Assert.assertEquals("SELECT *" + //
|
||||
"\nFROM t" + //
|
||||
"\nLIMIT 10", result);
|
||||
}
|
||||
|
||||
public void test_mysql_1() throws Exception {
|
||||
String sql = "select * from t";
|
||||
String result = PagerUtils.limit(sql, JdbcConstants.MYSQL, 10, 10);
|
||||
Assert.assertEquals("SELECT *" + //
|
||||
"\nFROM t" + //
|
||||
"\nLIMIT 10, 10", result);
|
||||
}
|
||||
|
||||
public void test_mysql_2() throws Exception {
|
||||
String sql = "select * from t";
|
||||
String result = PagerUtils.limit(sql, JdbcConstants.MYSQL, 20, 10);
|
||||
Assert.assertEquals("SELECT *" + //
|
||||
"\nFROM t" + //
|
||||
"\nLIMIT 20, 10", result);
|
||||
}
|
||||
|
||||
public void test_mysql_3() throws Exception {
|
||||
String sql = "select id, name, salary from t order by id, name";
|
||||
String result = PagerUtils.limit(sql, JdbcConstants.MYSQL, 20, 10);
|
||||
Assert.assertEquals("SELECT id, name, salary" + //
|
||||
"\nFROM t" + //
|
||||
"\nORDER BY id, name" + //
|
||||
"\nLIMIT 20, 10", result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user