Fix count query creation for simple select.

Closes: #3324
Original Pull Request: #3325
This commit is contained in:
Pranav
2024-01-19 16:15:28 +05:30
committed by Christoph Strobl
parent 9a781f783a
commit 1fbf778da2
2 changed files with 9 additions and 1 deletions

View File

@@ -81,6 +81,7 @@ import org.springframework.util.StringUtils;
* @author Vladislav Yukharin
* @author Chris Fraser
* @author Donghun Shin
* @author Pranav HS
*/
public abstract class QueryUtils {
@@ -156,7 +157,7 @@ public abstract class QueryUtils {
builder.append("\\s*");
builder.append("(select\\s+((distinct)?((?s).+?)?)\\s+)?(from\\s+");
builder.append(IDENTIFIER);
builder.append("(?:\\s+as)?\\s+)");
builder.append("(?:\\s+as)?\\s*)");
builder.append(IDENTIFIER_GROUP);
builder.append("(.*)");

View File

@@ -49,6 +49,7 @@ import org.springframework.data.jpa.domain.JpaSort;
* @author Chris Fraser
* @author Michał Pachucki
* @author Erik Pellizzon
* @author Pranav HS
*/
class QueryUtilsUnitTests {
@@ -934,4 +935,10 @@ class QueryUtilsUnitTests {
where name like :name
""", arg))).containsExactly("points");
}
@Test // GH-3324
void createCountQueryForSimpleQuery(){
String originalQuery = "select * from User";
assertCountQuery(originalQuery,"select count(*) from User");
}
}