mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for mapping
This commit is contained in:
@@ -5,6 +5,7 @@ import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.mapping.Entity;
|
||||
import com.alibaba.druid.mapping.MappingContext;
|
||||
import com.alibaba.druid.mapping.MappingEngine;
|
||||
import com.alibaba.druid.mapping.Property;
|
||||
import com.alibaba.druid.mapping.spi.OracleMappingProvider;
|
||||
@@ -27,13 +28,16 @@ public class MappingVisitorOracleTest extends TestCase {
|
||||
}
|
||||
|
||||
public void test_0() throws Exception {
|
||||
|
||||
MappingContext context = new MappingContext();
|
||||
context.setGenerateAlias(true);
|
||||
context.setExplainAllColumnToList(true);
|
||||
|
||||
Assert.assertEquals("SELECT serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device",
|
||||
engine.explainToSelectSQL("select *"));
|
||||
engine.explainToSelectSQL("select *", context));
|
||||
Assert.assertEquals("SELECT serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device\nWHERE ip = '127.0.0.1'",
|
||||
engine.explainToSelectSQL("select 编号, IP地址 WHERE IP地址 = '127.0.0.1'"));
|
||||
engine.explainToSelectSQL("select 编号, IP地址 WHERE IP地址 = '127.0.0.1'", context));
|
||||
Assert.assertEquals("SELECT serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device\nWHERE ip = '127.0.0.1'",
|
||||
engine.explainToSelectSQL("WHERE IP地址 = '127.0.0.1'"));
|
||||
engine.explainToSelectSQL("WHERE IP地址 = '127.0.0.1'", context));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.mapping.Entity;
|
||||
import com.alibaba.druid.mapping.MappingContext;
|
||||
import com.alibaba.druid.mapping.MappingEngine;
|
||||
import com.alibaba.druid.mapping.Property;
|
||||
import com.alibaba.druid.mapping.spi.MSSQLServerMappingProvider;
|
||||
@@ -26,22 +27,29 @@ public class MappingVisitorSQLServerTest extends TestCase {
|
||||
}
|
||||
|
||||
public void test_0() throws Exception {
|
||||
|
||||
Assert.assertEquals("SELECT serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device", engine.explainToSelectSQL("select *"));
|
||||
MappingContext context = new MappingContext();
|
||||
context.setGenerateAlias(true);
|
||||
context.setExplainAllColumnToList(true);
|
||||
|
||||
Assert.assertEquals("SELECT serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device", engine.explainToSelectSQL("select *", context));
|
||||
Assert.assertEquals("SELECT serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device\nWHERE ip = '127.0.0.1'",
|
||||
engine.explainToSelectSQL("select 编号, IP地址 WHERE IP地址 = '127.0.0.1'"));
|
||||
engine.explainToSelectSQL("select 编号, IP地址 WHERE IP地址 = '127.0.0.1'", context));
|
||||
|
||||
}
|
||||
|
||||
public void test_1() throws Exception {
|
||||
engine.setMaxLimit(10);
|
||||
|
||||
Assert.assertEquals("SELECT TOP 10 serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device", engine.explainToSelectSQL("select *"));
|
||||
MappingContext context = new MappingContext();
|
||||
context.setGenerateAlias(true);
|
||||
context.setExplainAllColumnToList(true);
|
||||
|
||||
Assert.assertEquals("SELECT TOP 10 serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device", engine.explainToSelectSQL("select *", context));
|
||||
Assert.assertEquals("SELECT TOP 10 serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device\nWHERE ip = '127.0.0.1'",
|
||||
engine.explainToSelectSQL("select 编号, IP地址 WHERE IP地址 = '127.0.0.1'"));
|
||||
engine.explainToSelectSQL("select 编号, IP地址 WHERE IP地址 = '127.0.0.1'", context));
|
||||
|
||||
Assert.assertEquals("SELECT TOP 3 serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device\nWHERE ip = '127.0.0.1'",
|
||||
engine.explainToSelectSQL("select top 3 编号, IP地址 WHERE IP地址 = '127.0.0.1'"));
|
||||
engine.explainToSelectSQL("select top 3 编号, IP地址 WHERE IP地址 = '127.0.0.1'", context));
|
||||
|
||||
engine.setMaxLimit(null);
|
||||
|
||||
|
||||
@@ -26,11 +26,11 @@ public class MappingVisitorTest extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
|
||||
Assert.assertEquals("SELECT serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device",
|
||||
Assert.assertEquals("SELECT *\nFROM device",
|
||||
engine.explainToSelectSQL("select *"));
|
||||
Assert.assertEquals("SELECT serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device\nWHERE ip = '127.0.0.1'",
|
||||
Assert.assertEquals("SELECT serviceTag, ip\nFROM device\nWHERE ip = '127.0.0.1'",
|
||||
engine.explainToSelectSQL("select 编号, IP地址 WHERE IP地址 = '127.0.0.1'"));
|
||||
Assert.assertEquals("SELECT serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device\nWHERE ip = '127.0.0.1'",
|
||||
Assert.assertEquals("SELECT *\nFROM device\nWHERE ip = '127.0.0.1'",
|
||||
engine.explainToSelectSQL("WHERE IP地址 = '127.0.0.1'"));
|
||||
|
||||
}
|
||||
@@ -53,11 +53,11 @@ public class MappingVisitorTest extends TestCase {
|
||||
public void test_1() throws Exception {
|
||||
engine.setMaxLimit(10);
|
||||
|
||||
Assert.assertEquals("SELECT serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device\nLIMIT 10",
|
||||
Assert.assertEquals("SELECT *\nFROM device\nLIMIT 10",
|
||||
engine.explainToSelectSQL("select *"));
|
||||
Assert.assertEquals("SELECT serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device\nWHERE ip = '127.0.0.1'\nLIMIT 10",
|
||||
Assert.assertEquals("SELECT serviceTag, ip\nFROM device\nWHERE ip = '127.0.0.1'\nLIMIT 10",
|
||||
engine.explainToSelectSQL("select 编号, IP地址 WHERE IP地址 = '127.0.0.1'"));
|
||||
Assert.assertEquals("SELECT serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device\nWHERE ip = '127.0.0.1'\nLIMIT 3",
|
||||
Assert.assertEquals("SELECT serviceTag, ip\nFROM device\nWHERE ip = '127.0.0.1'\nLIMIT 3",
|
||||
engine.explainToSelectSQL("select 编号, IP地址 WHERE IP地址 = '127.0.0.1' limit 3"));
|
||||
Assert.assertEquals(0, engine.exportParameters(engine.explainToSelectSQLObject("select 1")).size());
|
||||
Assert.assertEquals(0,
|
||||
|
||||
@@ -90,7 +90,7 @@ public class MySqlMappingShardingTest extends TestCase {
|
||||
|
||||
String sql = engine.explainToSelectSQL(oql, Collections.<Object> singletonList("b"));
|
||||
|
||||
String expected = "SELECT h.uid AS \"用户名\", u.name AS \"昵称\"\n" + //
|
||||
String expected = "SELECT h.uid, u.name\n" + //
|
||||
"FROM user_x u LEFT JOIN hero h ON h.uid = u.uid\n" + //
|
||||
"WHERE u.uid = 2";
|
||||
|
||||
@@ -115,7 +115,7 @@ public class MySqlMappingShardingTest extends TestCase {
|
||||
|
||||
String sql = engine.explainToSelectSQL(oql, Collections.<Object> singletonList("b"));
|
||||
|
||||
String expected = "SELECT h.uid AS \"用户名\", u.name AS \"昵称\"\n" + //
|
||||
String expected = "SELECT h.uid, u.name\n" + //
|
||||
"FROM user_x u LEFT JOIN hero h ON h.uid = u.uid\n" + //
|
||||
"WHERE uid = 2";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user