#1695 - For MySql like remove the binary keyword

This commit is contained in:
rob bygrave
2019-05-08 23:38:25 +12:00
parent 2648423930
commit b4782425f8
3 changed files with 52 additions and 40 deletions
@@ -1,7 +1,9 @@
package org.tests.query;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.DB;
import io.ebean.annotation.IgnorePlatform;
import io.ebean.annotation.Platform;
import org.junit.BeforeClass;
import org.junit.Test;
import org.tests.model.basic.Customer;
@@ -18,33 +20,35 @@ public class TestQueryFilterCaseInsensitive extends BaseTestCase {
ResetBasicData.reset();
}
@IgnorePlatform(Platform.MYSQL)
@Test
public void testEq() {
// Note: this test uses only customer#1..#4
List<Customer> customers = Ebean.find(Customer.class).where()
List<Customer> customers = DB.find(Customer.class).where()
.eq("name", "ROB") // case match
.le("id", 4).findList();
assertThat(customers).isEmpty();
customers = Ebean.find(Customer.class).where()
customers = DB.find(Customer.class).where()
.ieq("name", "ROB") // case insensitive match
.le("id", 4).findList();
assertThat(customers).hasSize(1);
}
@IgnorePlatform(Platform.MYSQL)
@Test
public void testNe() {
List<Customer> customers = Ebean.find(Customer.class).where()
List<Customer> customers = DB.find(Customer.class).where()
.ne("name", "ROB") // case match
.le("id", 4).findList();
assertThat(customers).hasSize(4);
customers = Ebean.find(Customer.class).where()
customers = DB.find(Customer.class).where()
.ine("name", "ROB") // case insensitive match
.le("id", 4).findList();
@@ -52,30 +56,32 @@ public class TestQueryFilterCaseInsensitive extends BaseTestCase {
}
@IgnorePlatform(Platform.MYSQL)
@Test
public void testLike() {
List<Customer> customers = Ebean.find(Customer.class).where()
List<Customer> customers = DB.find(Customer.class).where()
.like("name", "%O%") // case match
.le("id", 4).findList();
assertThat(customers).isEmpty();
customers = Ebean.find(Customer.class).where()
customers = DB.find(Customer.class).where()
.ilike("name", "%O%") // case insensitive match
.le("id", 4).findList();
assertThat(customers).hasSize(4); // Rob / Fiona / Cust No address / NocCust
}
@IgnorePlatform(Platform.MYSQL)
@Test
public void testContains() {
List<Customer> customers = Ebean.find(Customer.class).where()
List<Customer> customers = DB.find(Customer.class).where()
.contains("name", "O") // case match
.le("id", 4).findList();
assertThat(customers).isEmpty();
customers = Ebean.find(Customer.class).where()
customers = DB.find(Customer.class).where()
.icontains("name", "O") // case insensitive match
.le("id", 4).findList();
@@ -83,30 +89,32 @@ public class TestQueryFilterCaseInsensitive extends BaseTestCase {
}
@IgnorePlatform(Platform.MYSQL)
@Test
public void testStartsWith() {
List<Customer> customers = Ebean.find(Customer.class).where()
List<Customer> customers = DB.find(Customer.class).where()
.startsWith("name", "RO") // case match
.le("id", 4).findList();
assertThat(customers).isEmpty();
customers = Ebean.find(Customer.class).where()
customers = DB.find(Customer.class).where()
.istartsWith("name", "RO") // case insensitive match
.le("id", 4).findList();
assertThat(customers).hasSize(1);
}
@IgnorePlatform(Platform.MYSQL)
@Test
public void testEndsWith() {
List<Customer> customers = Ebean.find(Customer.class).where()
List<Customer> customers = DB.find(Customer.class).where()
.endsWith("name", "OB") // case match
.le("id", 4).findList();
assertThat(customers).isEmpty();
customers = Ebean.find(Customer.class).where()
customers = DB.find(Customer.class).where()
.iendsWith("name", "OB") // case insensitive match
.le("id", 4).findList();
@@ -1,6 +1,6 @@
package org.tests.query.other;
import io.ebean.Ebean;
import io.ebean.DB;
import io.ebean.TransactionalTestCase;
import org.tests.model.basic.Customer;
@@ -16,76 +16,80 @@ public class TestLikeEscaping extends TransactionalTestCase {
public void testLikeEscaping() {
// Mysql, PgSql, H2 special chars: "_" "%"
// MsSql special chars: "_" "%" "[" AND different Quoting!
Ebean.save(ResetBasicData.createCustomer("Paul % Percentage", "*Star", "[none]", 0, null));
Ebean.save(ResetBasicData.createCustomer("(none)", "More * Star", "[none]", 0, null));
DB.save(ResetBasicData.createCustomer("Paul % Percentage", "*Star", "[none]", 0, null));
DB.save(ResetBasicData.createCustomer("(none)", "More * Star", "[none]", 0, null));
Ebean.save(ResetBasicData.createCustomer("Paul %% Doublepercentage", "|Pipeway", "[other]", 1, null));
Ebean.save(ResetBasicData.createCustomer("_Udo Underscore", "|Pipeway", "[other]", 1, null));
DB.save(ResetBasicData.createCustomer("Paul %% Doublepercentage", "|Pipeway", "[other]", 1, null));
DB.save(ResetBasicData.createCustomer("_Udo Underscore", "|Pipeway", "[other]", 1, null));
Ebean.save(ResetBasicData.createCustomer("Bodo \\ backslash", "\\BS", "[other]", 1, null));
DB.save(ResetBasicData.createCustomer("Bodo \\ backslash", "\\BS", "[other]", 1, null));
assertThat(Ebean.find(Customer.class)
assertThat(DB.find(Customer.class)
.where().contains("name", "Paul %%").findCount()
).isEqualTo(1);
assertThat(Ebean.find(Customer.class)
assertThat(DB.find(Customer.class)
.where().contains("name", "o \\ b").findCount()
).isEqualTo(1);
assertThat(Ebean.find(Customer.class)
assertThat(DB.find(Customer.class)
.where().contains("name", "o \\\\ b").findCount()
).isEqualTo(0);
assertThat(Ebean.find(Customer.class)
assertThat(DB.find(Customer.class)
.where().startsWith("name", "_").findCount()
).isEqualTo(1);
assertThat(Ebean.find(Customer.class)
if (!isMySql()) {
assertThat(DB.find(Customer.class)
.where().startsWith("name", "_u").findCount()
).isEqualTo(0);
).isEqualTo(0);
}
assertThat(Ebean.find(Customer.class)
assertThat(DB.find(Customer.class)
.where().istartsWith("name", "_U").findCount()
).isEqualTo(1);
assertThat(Ebean.find(Customer.class)
if (!isMySql()) {
assertThat(DB.find(Customer.class)
.where().startsWith("shippingAddress.line1", "|p").findCount()
).isEqualTo(0);
).isEqualTo(0);
}
assertThat(Ebean.find(Customer.class)
assertThat(DB.find(Customer.class)
.where().startsWith("shippingAddress.line1", "|P").findCount()
).isEqualTo(2);
assertThat(Ebean.find(Customer.class)
assertThat(DB.find(Customer.class)
.where().startsWith("shippingAddress.line1", "\\B").findCount()
).isEqualTo(1);
assertThat(Ebean.find(Customer.class)
assertThat(DB.find(Customer.class)
.where().endsWith("billingAddress.line1", "]").findCount()
).isEqualTo(5);
assertThat(Ebean.find(Customer.class)
assertThat(DB.find(Customer.class)
.where().endsWith("billingAddress.line1", "[none]").findCount()
).isEqualTo(2);
assertThat(Ebean.find(Customer.class)
assertThat(DB.find(Customer.class)
.where().startsWith("billingAddress.line1", "[none]").findCount()
).isEqualTo(2);
assertThat(Ebean.find(Customer.class)
assertThat(DB.find(Customer.class)
.where().contains("billingAddress.line1", "[none]").findCount()
).isEqualTo(2);
assertThat(Ebean.find(Customer.class)
assertThat(DB.find(Customer.class)
.where().contains("shippingAddress.line1", "*").findCount()
).isEqualTo(2);
assertThat(Ebean.find(Customer.class)
assertThat(DB.find(Customer.class)
.where().startsWith("shippingAddress.line1", "*").findCount()
).isEqualTo(1);
assertThat(Ebean.find(Customer.class)
assertThat(DB.find(Customer.class)
.where().endsWith("shippingAddress.line1", "*").findCount()
).isEqualTo(0);
}