add PagerUtils

This commit is contained in:
wenshao
2013-02-02 13:48:48 +08:00
parent f83f076200
commit 21b8a41f4f
3 changed files with 145 additions and 17 deletions
+11 -1
View File
@@ -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);
}
}