mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Fix for #192 - Backslash literal in LIKE expression - Postgres (and H2, MySql) behaviour
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DeployPropertyParserMapTests {
|
||||
|
||||
@Test
|
||||
public void test_like_escape() {
|
||||
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("customer.name", "t1.name");
|
||||
map.put("id", "t0.id");
|
||||
|
||||
DeployPropertyParserMap parser = new DeployPropertyParserMap(map);
|
||||
|
||||
String output = parser.parse("(lower(customer.name) like ? escape'' or id > ?)");
|
||||
|
||||
System.out.println(output);
|
||||
Assert.assertEquals("(lower(t1.name) like ? escape'' or t0.id > ?)", output);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,8 +16,6 @@ public class TestExprNestedDisjunction extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
// java.sql.Date dateAfter = java.sql.Date.valueOf("2010-01-01");
|
||||
|
||||
java.sql.Date onAfter = java.sql.Date.valueOf("2009-08-31");
|
||||
|
||||
Query<Customer> q = Ebean.find(Customer.class).where().disjunction()
|
||||
@@ -28,8 +26,8 @@ public class TestExprNestedDisjunction extends BaseTestCase {
|
||||
q.findList();
|
||||
String s = q.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(s
|
||||
.contains("(t0.name like ? and t0.anniversary = ? ) or (t0.status = ? and t0.id > ? )"));
|
||||
Assert.assertTrue(s.contains("(t0.name like ? "));
|
||||
Assert.assertTrue(s.contains(" and t0.anniversary = ? ) or (t0.status = ? and t0.id > ? )"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class TestQueryManyToOneWhereClauseJoin extends BaseTestCase {
|
||||
query.findList();
|
||||
|
||||
//select t0.id c0, t0.status c1, t0.order_date c2, t0.ship_date c3, t1.name c4, t0.cretime c5, t0.updtime c6, t0.kcustomer_id c7
|
||||
String expectedSql = "from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where (lower(t1.name) like ? or t0.id > ? ) ";
|
||||
String expectedSql = "from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where (lower(t1.name) like ? ";
|
||||
Assert.assertTrue(query.getGeneratedSql().contains(expectedSql));
|
||||
|
||||
// select t0.id c0, t0.status c1, t0.order_date c2, t0.ship_date c3, t1.name c4, t0.cretime c5, t0.updtime c6, t0.kcustomer_id c7
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.avaje.tests.query.other;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.EBasic;
|
||||
|
||||
public class TestWhereLikeWithSlash extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
EBasic basic = new EBasic();
|
||||
basic.setName("slash\\monkey");
|
||||
|
||||
Ebean.save(basic);
|
||||
|
||||
|
||||
Query<EBasic> query = Ebean.find(EBasic.class).where().like("name", "slash\\mon%").query();
|
||||
|
||||
List<EBasic> list = query.findList();
|
||||
|
||||
Assert.assertEquals(1, list.size());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user