mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
Refactor tidy sql generated by InQueryExpression
Remove excess padding and () around the property name
This commit is contained in:
1 parent
391b33beae
commit
6f5e144a93
3 files changed
+13
-13
No files matched your search
@@ -75,7 +75,7 @@ final class InQueryExpression extends AbstractExpression implements UnsupportedD
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addSql(SpiExpressionRequest request) {
|
public void addSql(SpiExpressionRequest request) {
|
||||||
request.append(" (").append(propName).append(")");
|
request.append(propName);
|
||||||
if (not) {
|
if (not) {
|
||||||
request.append(" not");
|
request.append(" not");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class TestQueryAlias extends BaseTestCase {
|
|||||||
// where (myt0.one_key) in (select st0.one_key from ckey_parent st0)
|
// where (myt0.one_key) in (select st0.one_key from ckey_parent st0)
|
||||||
|
|
||||||
assertThat(sql).contains("ckey_parent myt0");
|
assertThat(sql).contains("ckey_parent myt0");
|
||||||
assertThat(sql).contains("(myt0.one_key) in (select st0.one_key from ckey_parent st0)");
|
assertThat(sql).contains("myt0.one_key in (select st0.one_key from ckey_parent st0)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@IgnorePlatform(Platform.COCKROACH)
|
@IgnorePlatform(Platform.COCKROACH)
|
||||||
@@ -56,7 +56,7 @@ public class TestQueryAlias extends BaseTestCase {
|
|||||||
String sql = pq.getGeneratedSql();
|
String sql = pq.getGeneratedSql();
|
||||||
|
|
||||||
assertThat(sql).contains("ckey_parent myt0");
|
assertThat(sql).contains("ckey_parent myt0");
|
||||||
assertThat(sql).contains("(concat(myt0.one_key,myt0.two_key)) in (select concat(st0.one_key,st0.two_key) from ckey_parent st0)");
|
assertThat(sql).contains("concat(myt0.one_key,myt0.two_key) in (select concat(st0.one_key,st0.two_key) from ckey_parent st0)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -82,7 +82,7 @@ public class TestQueryAlias extends BaseTestCase {
|
|||||||
// where (myt0.one_key) in (select st0.one_key from ckey_parent st0)
|
// where (myt0.one_key) in (select st0.one_key from ckey_parent st0)
|
||||||
|
|
||||||
assertThat(sql).contains("ckey_parent myt0");
|
assertThat(sql).contains("ckey_parent myt0");
|
||||||
assertThat(sql).contains("(myt0.one_key) not in (select st0.one_key from ckey_parent st0)");
|
assertThat(sql).contains("myt0.one_key not in (select st0.one_key from ckey_parent st0)");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -28,9 +28,9 @@ public class TestSubQuery extends BaseTestCase {
|
|||||||
Query<Order> query = DB.find(Order.class).where().in("id", sq).query();
|
Query<Order> query = DB.find(Order.class).where().in("id", sq).query();
|
||||||
query.findList();
|
query.findList();
|
||||||
if (isPostgresCompatible()) {
|
if (isPostgresCompatible()) {
|
||||||
assertThat(query.getGeneratedSql()).isEqualTo("select t0.id, t0.status, t0.order_date, t0.ship_date, t1.name, t0.cretime, t0.updtime, t0.kcustomer_id from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where (t0.id) in (select distinct t0.id from o_order t0 join o_order_detail u1 on u1.order_id = t0.id and u1.id > 0 where u1.product_id = any(?))");
|
assertThat(query.getGeneratedSql()).isEqualTo("select t0.id, t0.status, t0.order_date, t0.ship_date, t1.name, t0.cretime, t0.updtime, t0.kcustomer_id from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where t0.id in (select distinct t0.id from o_order t0 join o_order_detail u1 on u1.order_id = t0.id and u1.id > 0 where u1.product_id = any(?))");
|
||||||
} else {
|
} else {
|
||||||
assertThat(query.getGeneratedSql()).isEqualTo("select t0.id, t0.status, t0.order_date, t0.ship_date, t1.name, t0.cretime, t0.updtime, t0.kcustomer_id from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where (t0.id) in (select distinct t0.id from o_order t0 join o_order_detail u1 on u1.order_id = t0.id and u1.id > 0 where u1.product_id in (?,?,?))");
|
assertThat(query.getGeneratedSql()).isEqualTo("select t0.id, t0.status, t0.order_date, t0.ship_date, t1.name, t0.cretime, t0.updtime, t0.kcustomer_id from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where t0.id in (select distinct t0.id from o_order t0 join o_order_detail u1 on u1.order_id = t0.id and u1.id > 0 where u1.product_id in (?,?,?))");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,9 +84,9 @@ public class TestSubQuery extends BaseTestCase {
|
|||||||
query.findSingleAttribute();
|
query.findSingleAttribute();
|
||||||
|
|
||||||
if (isPostgresCompatible()) {
|
if (isPostgresCompatible()) {
|
||||||
assertThat(query.getGeneratedSql()).isEqualTo("select t0.ship_date from o_order t0 where (t0.id) in (" + debugSq.getGeneratedSql() + ")");
|
assertThat(query.getGeneratedSql()).isEqualTo("select t0.ship_date from o_order t0 where t0.id in (" + debugSq.getGeneratedSql() + ")");
|
||||||
} else {
|
} else {
|
||||||
assertSql(query.getGeneratedSql()).isEqualTo("select t0.ship_date from o_order t0 where (t0.id) in (" + trimSql(debugSq.getGeneratedSql()) + ")");
|
assertSql(query.getGeneratedSql()).isEqualTo("select t0.ship_date from o_order t0 where t0.id in (" + trimSql(debugSq.getGeneratedSql()) + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ public class TestSubQuery extends BaseTestCase {
|
|||||||
Query<Order> query = DB.find(Order.class).select("status").where().isIn("shipDate", sq).query();
|
Query<Order> query = DB.find(Order.class).select("status").where().isIn("shipDate", sq).query();
|
||||||
query.findSingleAttribute();
|
query.findSingleAttribute();
|
||||||
assertSql(query.getGeneratedSql())
|
assertSql(query.getGeneratedSql())
|
||||||
.isEqualTo("select t0.status from o_order t0 where (t0.ship_date) in (" + trimSql(debugSq.getGeneratedSql()) + ")");
|
.isEqualTo("select t0.status from o_order t0 where t0.ship_date in (" + trimSql(debugSq.getGeneratedSql()) + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,7 +131,7 @@ public class TestSubQuery extends BaseTestCase {
|
|||||||
query.findSingleAttribute();
|
query.findSingleAttribute();
|
||||||
|
|
||||||
assertSql(query.getGeneratedSql())
|
assertSql(query.getGeneratedSql())
|
||||||
.isEqualTo("select t0.ship_time from or_order_ship t0 where (t0.id) in (" + trimSql(debugSq.getGeneratedSql()) + ")");
|
.isEqualTo("select t0.ship_time from or_order_ship t0 where t0.id in (" + trimSql(debugSq.getGeneratedSql()) + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCompositeKey() {
|
public void testCompositeKey() {
|
||||||
@@ -192,7 +192,7 @@ public class TestSubQuery extends BaseTestCase {
|
|||||||
// TODO: If, after bugfixing, the system still join against vehicle I do not
|
// TODO: If, after bugfixing, the system still join against vehicle I do not
|
||||||
// know now, in our case, it is not necessary if not
|
// know now, in our case, it is not necessary if not
|
||||||
// using it in the where clause
|
// using it in the where clause
|
||||||
String golden = "(t0.id) in (select t0.vehicle_id from vehicle_driver t0 left join vehicle t1 on t1.id = t0.vehicle_id )";
|
String golden = "t0.id in (select t0.vehicle_id from vehicle_driver t0 left join vehicle t1 on t1.id = t0.vehicle_id )";
|
||||||
assertThat(sql).contains(golden);
|
assertThat(sql).contains(golden);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -213,7 +213,7 @@ public class TestSubQuery extends BaseTestCase {
|
|||||||
pq.findList();
|
pq.findList();
|
||||||
|
|
||||||
String sql = pq.getGeneratedSql();
|
String sql = pq.getGeneratedSql();
|
||||||
String golden = "(t0.id) in (select t0.vehicle_id from vehicle_driver t0 left join vehicle t1 on t1.id = t0.vehicle_id where t1.license_number = ? )";
|
String golden = "t0.id in (select t0.vehicle_id from vehicle_driver t0 left join vehicle t1 on t1.id = t0.vehicle_id where t1.license_number = ? )";
|
||||||
assertThat(sql).contains(golden);
|
assertThat(sql).contains(golden);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,7 +235,7 @@ public class TestSubQuery extends BaseTestCase {
|
|||||||
|
|
||||||
String sql = pq.getGeneratedSql();
|
String sql = pq.getGeneratedSql();
|
||||||
|
|
||||||
String golden = "(t0.id) in (select t0.vehicle_id from vehicle_driver t0 left join vehicle t1 on t1.id = t0.vehicle_id )";
|
String golden = "t0.id in (select t0.vehicle_id from vehicle_driver t0 left join vehicle t1 on t1.id = t0.vehicle_id )";
|
||||||
assertThat(sql).contains(golden);
|
assertThat(sql).contains(golden);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user