-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HHH-18033 Fix LimitHandler detect wrong statement end if sql contains quoted semicolon #8270
Merged
+314
−23
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
22 changes: 22 additions & 0 deletions
22
...munity-dialects/src/test/java/org/hibernate/community/dialect/IngresLimitHandlerTest.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.community.dialect; | ||
|
||
import org.hibernate.community.dialect.pagination.IngresLimitHandler; | ||
import org.hibernate.dialect.pagination.AbstractLimitHandler; | ||
import org.hibernate.orm.test.dialect.AbstractLimitHandlerTest; | ||
|
||
/** | ||
* @author Yanming Zhou | ||
*/ | ||
public class IngresLimitHandlerTest extends AbstractLimitHandlerTest { | ||
|
||
@Override | ||
protected AbstractLimitHandler getLimitHandler() { | ||
return IngresLimitHandler.INSTANCE; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ommunity-dialects/src/test/java/org/hibernate/community/dialect/RowsLimitHandlerTest.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,27 @@ | ||
/* | ||
* 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.community.dialect; | ||
|
||
import org.hibernate.community.dialect.pagination.RowsLimitHandler; | ||
import org.hibernate.dialect.pagination.AbstractLimitHandler; | ||
import org.hibernate.orm.test.dialect.AbstractLimitHandlerTest; | ||
|
||
/** | ||
* @author Yanming Zhou | ||
*/ | ||
public class RowsLimitHandlerTest extends AbstractLimitHandlerTest { | ||
|
||
@Override | ||
protected AbstractLimitHandler getLimitHandler() { | ||
return RowsLimitHandler.INSTANCE; | ||
} | ||
|
||
@Override | ||
protected String getLimitClause() { | ||
return " rows ?"; | ||
} | ||
} |
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
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
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
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
73 changes: 73 additions & 0 deletions
73
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,73 @@ | ||
/* | ||
* 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.LimitHandler; | ||
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler; | ||
import org.hibernate.query.spi.Limit; | ||
import org.hibernate.query.spi.QueryOptions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hibernate.dialect.pagination.AbstractLimitHandler.hasFirstRow; | ||
import static org.hibernate.dialect.pagination.AbstractLimitHandler.hasMaxRows; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* @author Yanming Zhou | ||
*/ | ||
public 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 ';'" + getLimitClause(); | ||
assertGenerateExpectedSql(expected, sql); | ||
|
||
sql = "select * from Person p where p.name like ';' "; | ||
expected = "select * from Person p where p.name like ';'" + getLimitClause() + " "; | ||
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 ';'" + getLimitClause() + ";"; | ||
assertGenerateExpectedSql(expected, sql); | ||
|
||
sql = "select * from Person p where p.name like ';' ; "; | ||
expected = "select * from Person p where p.name like ';'" + getLimitClause() + " ; "; | ||
assertGenerateExpectedSql(expected, sql); | ||
} | ||
|
||
protected void assertGenerateExpectedSql(String expected, String sql) { | ||
assertEquals(expected, getLimitHandler().processSql(sql, getLimit(), QueryOptions.NONE)); | ||
} | ||
|
||
protected abstract LimitHandler getLimitHandler(); | ||
|
||
protected Limit getLimit() { | ||
return new Limit(0, 10); | ||
} | ||
|
||
protected String getLimitClause() { | ||
LimitHandler handler = getLimitHandler(); | ||
if (handler instanceof OffsetFetchLimitHandler) { | ||
OffsetFetchLimitHandler oflh = (OffsetFetchLimitHandler) handler; | ||
Limit limit = getLimit(); | ||
if (hasFirstRow(limit) && hasMaxRows(limit)) { | ||
return " offset " + (oflh.supportsVariableLimit() ? "?" : String.valueOf(limit.getFirstRow())) | ||
+ " rows fetch next " + (oflh.supportsVariableLimit() ? "?" : String.valueOf(limit.getMaxRows())) + " rows only"; | ||
} | ||
else if (hasFirstRow(limit)) { | ||
return " offset " + (oflh.supportsVariableLimit() ? "?" : String.valueOf(limit.getFirstRow())) + " rows"; | ||
} else { | ||
return " fetch first " + (oflh.supportsVariableLimit() ? "?" : String.valueOf(limit.getMaxRows())) + " rows only"; | ||
} | ||
} | ||
return " limit ?"; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
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,21 @@ | ||
/* | ||
* 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; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
hibernate-core/src/test/java/org/hibernate/orm/test/dialect/DerbyLimitHandlerTest.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,21 @@ | ||
/* | ||
* 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.DerbyLimitHandler; | ||
|
||
/** | ||
* @author Yanming Zhou | ||
*/ | ||
public class DerbyLimitHandlerTest extends AbstractLimitHandlerTest { | ||
|
||
@Override | ||
protected AbstractLimitHandler getLimitHandler() { | ||
return DerbyLimitHandler.INSTANCE; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
hibernate-core/src/test/java/org/hibernate/orm/test/dialect/LimitLimitHandlerTest.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,21 @@ | ||
/* | ||
* 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.LimitLimitHandler; | ||
|
||
/** | ||
* @author Yanming Zhou | ||
*/ | ||
public class LimitLimitHandlerTest extends AbstractLimitHandlerTest { | ||
|
||
@Override | ||
protected AbstractLimitHandler getLimitHandler() { | ||
return LimitLimitHandler.INSTANCE; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
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,21 @@ | ||
/* | ||
* 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; | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be in a test package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other tests already exist in this package, I think it's better to keep it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, well. That doesn't seem quite right to me.
@beikov is there a good reason the tests for the community dialects are in the same package as the dialect classes? Shouldn't they be somewhere like
org.hibernate.community.dialect.test
or whatever?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having tests in the same package as the Dialect under test allows to test package-private methods, which I suppose was the original reason for doing this. When we moved the classes to the community dialects module, we didn't change the package for tests apparently. Either is fine IMO, though if you want to change it, I think I'd prefer the package you are proposing.