Render entire statement after applying sort.
This commit makes sure to render the entire statement after applying the sort expression via the QueryEnhancer. Previously only parts, the actual statement body, had been considered. Closes: #3263 Original Pull Request: #3264
This commit is contained in:
@@ -141,7 +141,7 @@ public class JSqlParserQueryEnhancer implements QueryEnhancer {
|
||||
|
||||
selectBody.getOrderByElements().addAll(orderByElements);
|
||||
|
||||
return selectBody.toString();
|
||||
return selectStatement.toString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -179,6 +179,17 @@ class QueryEnhancerUnitTests {
|
||||
assertThat(query).endsWithIgnoringCase("ORDER BY p.firstname, p.lastname asc");
|
||||
}
|
||||
|
||||
@Test // GH-3263
|
||||
void preserveSourceQueryWhenAddingSort() {
|
||||
|
||||
StringQuery query = new StringQuery("WITH all_projects AS (SELECT * FROM projects) SELECT * FROM all_projects p",
|
||||
true);
|
||||
|
||||
assertThat(getEnhancer(query).applySorting(Sort.by("name"), "p")) //
|
||||
.startsWithIgnoringCase(query.getQueryString())
|
||||
.endsWithIgnoringCase("ORDER BY p.name ASC");
|
||||
}
|
||||
|
||||
@Test // GH-2812
|
||||
void createCountQueryFromDeleteQuery() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user