HHH-10736

- Provide test case for situations when \r\n is used as a line separator
- Add a temporary "fix" to demonstrate how we can handle the issue
This commit is contained in:
Vlad Mihalcea 2016-05-19 15:23:03 +03:00 committed by Chris Cranford
parent e2c5b34093
commit 2315a5fcbf
2 changed files with 7 additions and 5 deletions

View File

@ -191,8 +191,9 @@ public class SQLServer2005LimitHandler extends AbstractLimitHandler {
String alias = getAlias( expression );
if ( alias == null ) {
// Inserting alias. It is unlikely that we would have to add alias, but just in case.
endPos = shallowIndexOfPattern( sb, Pattern.compile("(\\s+" + FROM + ")", Pattern.CASE_INSENSITIVE), startPos );
alias = StringHelper.generateAlias( "page", unique );
sb.insert( endPos - 1, " as " + alias );
sb.insert( endPos, " as " + alias );
}
aliases.add( alias );
}

View File

@ -7,15 +7,16 @@
package org.hibernate.dialect;
import java.util.Locale;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.engine.spi.RowSelection;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@ -74,7 +75,7 @@ public class SQLServer2005DialectTestCase extends BaseUnitTestCase {
@Test
@TestForIssue(jiraKey = "HHH-8507")
public void testGetLimitStringWithNewlineAfterColumnList() {
final String query = "select E.fieldA,E.fieldB" + System.lineSeparator() + "FROM Employee E WHERE E.firstName = :firstName";
final String query = "select E.fieldA,E.fieldB\r\nFROM Employee E WHERE E.firstName = :firstName";
assertEquals(
"WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " +
"select E.fieldA as page0_,E.fieldB as page1_" + System.lineSeparator() +