add PagerUtils

This commit is contained in:
wenshao
2013-02-02 13:51:39 +08:00
parent 21b8a41f4f
commit 1fa03bb01e
2 changed files with 2 additions and 2 deletions
@@ -0,0 +1,54 @@
package com.alibaba.druid.bvt.sql;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.sql.PagerUtils;
import com.alibaba.druid.util.JdbcConstants;
public class PagerUtilsTest0 extends TestCase {
public void test_mysql_0() throws Exception {
String sql = "select * from t";
String result = PagerUtils.count(sql, JdbcConstants.MYSQL);
Assert.assertEquals("SELECT COUNT(*)\n" + //
"FROM t", result);
}
public void test_mysql_1() throws Exception {
String sql = "select id, name from t";
String result = PagerUtils.count(sql, JdbcConstants.MYSQL);
Assert.assertEquals("SELECT COUNT(*)\n" + //
"FROM t", result);
}
public void test_mysql_2() throws Exception {
String sql = "select id, name from t order by id";
String result = PagerUtils.count(sql, JdbcConstants.MYSQL);
Assert.assertEquals("SELECT COUNT(*)\n" + //
"FROM t", result);
}
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" + //
"FROM (SELECT id, name" + //
"\n\tFROM t1" + //
"\n\tUNION" + //
"\n\tSELECT id, name" + //
"\n\tFROM t2" + //
"\n\t)", result);
}
}
@@ -0,0 +1,44 @@
package com.alibaba.druid.bvt.sql;
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);
}
}