-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-18033 Fix AbstractLimitHandler detect wrong statement end if sql …
…contains quoted semicolon
- Loading branch information
Showing
4 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
hibernate-core/src/test/java/org/hibernate/orm/test/dialect/AbstractLimitHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html | ||
*/ | ||
package org.hibernate.orm.test.dialect; | ||
|
||
import org.hibernate.dialect.pagination.AbstractLimitHandler; | ||
import org.hibernate.query.spi.Limit; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* @author Yanming Zhou | ||
*/ | ||
abstract class AbstractLimitHandlerTest { | ||
|
||
@Test | ||
public void testSqlWithSemicolonInsideQuotedString() { | ||
String sql = "select * from Person p where p.name like ';'"; | ||
String expected = "select * from Person p where p.name like ';' fetch first ? rows only"; | ||
assertGenerateExpectedSql(expected, sql); | ||
} | ||
|
||
@Test | ||
public void testSqlWithSemicolonInsideQuotedStringAndEndsWithSemicolon() { | ||
String sql = "select * from Person p where p.name like ';';"; | ||
String expected = "select * from Person p where p.name like ';' fetch first ? rows only;"; | ||
assertGenerateExpectedSql(expected, sql); | ||
} | ||
|
||
protected void assertGenerateExpectedSql(String expected, String sql) { | ||
assertEquals(expected, getLimitHandler().processSql(sql, new Limit(0, 10))); | ||
} | ||
|
||
protected abstract AbstractLimitHandler getLimitHandler(); | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
hibernate-core/src/test/java/org/hibernate/orm/test/dialect/DB2LimitHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html | ||
*/ | ||
package org.hibernate.orm.test.dialect; | ||
|
||
import org.hibernate.dialect.pagination.AbstractLimitHandler; | ||
import org.hibernate.dialect.pagination.DB2LimitHandler; | ||
|
||
/** | ||
* @author Yanming Zhou | ||
*/ | ||
public class DB2LimitHandlerTest extends AbstractLimitHandlerTest { | ||
|
||
@Override | ||
protected AbstractLimitHandler getLimitHandler() { | ||
return DB2LimitHandler.INSTANCE; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
hibernate-core/src/test/java/org/hibernate/orm/test/dialect/OffsetFetchLimitHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html | ||
*/ | ||
package org.hibernate.orm.test.dialect; | ||
|
||
import org.hibernate.dialect.pagination.AbstractLimitHandler; | ||
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler; | ||
|
||
/** | ||
* @author Yanming Zhou | ||
*/ | ||
public class OffsetFetchLimitHandlerTest extends AbstractLimitHandlerTest { | ||
|
||
@Override | ||
protected AbstractLimitHandler getLimitHandler() { | ||
return OffsetFetchLimitHandler.INSTANCE; | ||
} | ||
|
||
} |