From 6b928f93798d6bdffec9120bcb5795c84272b59c Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Fri, 16 Dec 2016 12:51:22 -0500 Subject: [PATCH] HHH-11324 - Added test cases. (cherry picked from commit db1dfd6908e9c1a9840467a8758eafde68477dbe) --- .../dialect/SQLServer2005DialectTestCase.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java index 043876465c..7800016ec7 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java @@ -296,6 +296,30 @@ public class SQLServer2005DialectTestCase extends BaseUnitTestCase { ); } + @Test + @TestForIssue(jiraKey = "HHH-11324") + public void testGetLimitStringWithSelectClauseNestedQueryUsingParenthesis() { + final String query = "select t1.c1 as col_0_0, (select case when count(t2.c1)>0 then 'ADDED' else 'UNMODIFIED' end from table2 t2 WHERE (t2.c1 in (?))) as col_1_0 from table1 t1 WHERE 1=1 ORDER BY t1.c1 ASC"; + + assertEquals( + "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + + "select TOP(?) t1.c1 as col_0_0, (select case when count(t2.c1)>0 then 'ADDED' else 'UNMODIFIED' end from table2 t2 WHERE (t2.c1 in (?))) as col_1_0 from table1 t1 WHERE 1=1 ORDER BY t1.c1 ASC ) inner_query ) " + + "SELECT col_0_0, col_1_0 FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + dialect.getLimitHandler().processSql( query, toRowSelection( 1, 5 ) ) + ); + } + + @Test + @TestForIssue(jiraKey = "HHH-11324") + public void testGetLimitStringWithSelectClauseNestedQueryUsingParenthesisOnlyTop() { + final String query = "select t1.c1 as col_0_0, (select case when count(t2.c1)>0 then 'ADDED' else 'UNMODIFIED' end from table2 t2 WHERE (t2.c1 in (?))) as col_1_0 from table1 t1 WHERE 1=1 ORDER BY t1.c1 ASC"; + + assertEquals( + "select TOP(?) t1.c1 as col_0_0, (select case when count(t2.c1)>0 then 'ADDED' else 'UNMODIFIED' end from table2 t2 WHERE (t2.c1 in (?))) as col_1_0 from table1 t1 WHERE 1=1 ORDER BY t1.c1 ASC", + dialect.getLimitHandler().processSql( query, toRowSelection( 0, 5 ) ) + ); + } + @Test @TestForIssue(jiraKey = "HHH-9635") public void testAppendLockHintReadPastLocking() {