From b4782425f8c5c7b0c2941f94107ee353fc81737d Mon Sep 17 00:00:00 2001 From: rob bygrave Date: Wed, 8 May 2019 23:38:25 +1200 Subject: [PATCH] #1695 - For MySql like remove the binary keyword --- .../dbplatform/mysql/MySqlPlatform.java | 6 +-- .../query/TestQueryFilterCaseInsensitive.java | 34 +++++++----- .../tests/query/other/TestLikeEscaping.java | 52 ++++++++++--------- 3 files changed, 52 insertions(+), 40 deletions(-) diff --git a/src/main/java/io/ebean/config/dbplatform/mysql/MySqlPlatform.java b/src/main/java/io/ebean/config/dbplatform/mysql/MySqlPlatform.java index 9ee373288..e9c769095 100644 --- a/src/main/java/io/ebean/config/dbplatform/mysql/MySqlPlatform.java +++ b/src/main/java/io/ebean/config/dbplatform/mysql/MySqlPlatform.java @@ -35,7 +35,7 @@ public class MySqlPlatform extends DatabasePlatform { this.dbIdentity.setSupportsGetGeneratedKeys(true); this.dbIdentity.setSupportsIdentity(true); this.dbIdentity.setSupportsSequence(false); - + this.dbDefaultValue.setNow("now(6)"); // must have same precision as TIMESTAMP this.dbDefaultValue.setFalse("0"); this.dbDefaultValue.setTrue("1"); @@ -51,8 +51,8 @@ public class MySqlPlatform extends DatabasePlatform { this.openQuote = "`"; this.closeQuote = "`"; // use pipe for escaping as it depends if mysql runs in no_backslash_escapes or not. - this.likeClauseRaw = "like binary ? escape ''"; - this.likeClauseEscaped = "like binary ? escape '|'"; + this.likeClauseRaw = "like ? escape ''"; + this.likeClauseEscaped = "like ? escape '|'"; this.forwardOnlyHintOnFindIterate = true; this.booleanDbType = Types.BIT; diff --git a/src/test/java/org/tests/query/TestQueryFilterCaseInsensitive.java b/src/test/java/org/tests/query/TestQueryFilterCaseInsensitive.java index 8d606cc4b..a9bb3687d 100644 --- a/src/test/java/org/tests/query/TestQueryFilterCaseInsensitive.java +++ b/src/test/java/org/tests/query/TestQueryFilterCaseInsensitive.java @@ -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 customers = Ebean.find(Customer.class).where() + List 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 customers = Ebean.find(Customer.class).where() + List 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 customers = Ebean.find(Customer.class).where() + List 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 customers = Ebean.find(Customer.class).where() + List 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 customers = Ebean.find(Customer.class).where() + List 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 customers = Ebean.find(Customer.class).where() + List 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(); diff --git a/src/test/java/org/tests/query/other/TestLikeEscaping.java b/src/test/java/org/tests/query/other/TestLikeEscaping.java index 2592ad098..ceebbcddc 100644 --- a/src/test/java/org/tests/query/other/TestLikeEscaping.java +++ b/src/test/java/org/tests/query/other/TestLikeEscaping.java @@ -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); }