Skip to content

Commit

Permalink
Remove extra space added to the generated SQL via the LIKE expression
Browse files Browse the repository at this point in the history
  • Loading branch information
rbygrave committed Aug 18, 2023
1 parent eb0812d commit 0e9fe6a
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public String parseDeploy(String logicalProp) {
public void appendLike(boolean rawLikeExpression) {
sql.append(" ");
sql.append(queryRequest.dbLikeClause(rawLikeExpression));
sql.append(" ");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ void where_withParams() {
final Query<Customer> query = where("id isNotNull and name = ? and smallnote istartsWith ?", "Rob", "Foo");
query.findList();
if (isH2()) {
assertSql(query).contains("where (t0.id is not null and t0.name = ? and lower(t0.smallnote) like ? escape'|' )");
assertSql(query).contains("where (t0.id is not null and t0.name = ? and lower(t0.smallnote) like ? escape'|')");
}
}

Expand All @@ -757,7 +757,7 @@ void where_withParamsQuPos() {
final Query<Customer> query = where("name = ?1 and smallnote istartsWith ?2 and name like ?1", "Rob", "Foo");
query.findList();
if (isH2()) {
assertSql(query).contains(" where (t0.name = ? and lower(t0.smallnote) like ? escape'|' and t0.name like ? escape'' )");
assertSql(query).contains(" where (t0.name = ? and lower(t0.smallnote) like ? escape'|' and t0.name like ? escape'')");
}
}

Expand All @@ -775,7 +775,7 @@ void where_orWithParams() {
final Query<Customer> query = where("(id isNotNull or name = ?) and smallnote istartsWith ?", "Rob", "Foo");
query.findList();
if (isH2()) {
assertSql(query).contains("where ((t0.id is not null or t0.name = ?) and lower(t0.smallnote) like ? escape'|' )");
assertSql(query).contains("where ((t0.id is not null or t0.name = ?) and lower(t0.smallnote) like ? escape'|')");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void test() throws InterruptedException {

if (isH2()) {
assertThat(sql).hasSize(2);
assertSql(sql.get(0)).contains("from hi_tone_with_history t0 where (t0.sys_period_start <= ? and (t0.sys_period_end is null or t0.sys_period_end > ?)) and lower(t0.name) like ? escape'' limit 10");
assertSql(sql.get(0)).contains("from hi_tone_with_history t0 where (t0.sys_period_start <= ? and (t0.sys_period_end is null or t0.sys_period_end > ?)) and lower(t0.name) like ? escape'' limit 10");
assertSql(sql.get(1)).contains("from hi_ttwo_with_history t0 left join hi_tthree_with_history t1 on t1.hi_ttwo_id = t0.id and (t1.sys_period_start <= ? and (t1.sys_period_end is null or t1.sys_period_end > ?)) where (t0.sys_period_start <= ? and (t0.sys_period_end is null or t0.sys_period_end > ?)) and (t0.hi_tone_id) in (?)");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public void testFilterManyUsingExpression() {
if (isSqlServer()) {
assertSql(sql.get(0)).contains(" from o_customer t0 left join contact t1 on t1.customer_id = t0.id where (t1.first_name is not null and lower(t1.email) like ? ) order by t0.id; --bind(rob%)");
} else {
assertSql(sql.get(0)).contains(" from o_customer t0 left join contact t1 on t1.customer_id = t0.id where (t1.first_name is not null and lower(t1.email) like ? escape'|' ) order by t0.id; --bind(rob%)");
assertSql(sql.get(0)).contains(" from o_customer t0 left join contact t1 on t1.customer_id = t0.id where (t1.first_name is not null and lower(t1.email) like ? escape'|') order by t0.id; --bind(rob%)");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public void test_metricsAsJson_withAll() {
assertThat(metricsJson).contains("\"name\":\"orm.Customer.findList\"");
assertThat(metricsJson).contains("\"loc\":\"org.tests.model.basic.finder.CustomerFinder.byNameStatus\"");
if (isH2() || isPostgresCompatible()) {
assertThat(metricsJson).contains("\"hash\":\"de3affa5b4bff07e19c1c012590dcde6\"");
assertThat(metricsJson).contains("\"hash\":\"25c7fe502c5a20ebe5b13db21e70e6a9\"");
assertThat(metricsJson).contains("\"sql\":\"select t0.id, t0.status,");
}
}
Expand Down

0 comments on commit 0e9fe6a

Please sign in to comment.