Skip to content

Commit

Permalink
Refine default cursor preference when using FOR JSON/FOR XML.
Browse files Browse the repository at this point in the history
We now no longer prefer cursor usage by default when the statement ends with a FOR XML/JSON clause to avoid server side errors reporting that cursor usage is not supported.

[resolves #209]

Signed-off-by: Mark Paluch <[email protected]>
  • Loading branch information
mp911de committed Nov 9, 2021
1 parent 1da30e5 commit 43a77a7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/main/java/io/r2dbc/mssql/SimpleMssqlStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,13 @@ static boolean prefersCursors(String sql) {
return false;
}

char c = sql.charAt(0);
String lc = sql.trim().toLowerCase(Locale.ENGLISH);
if (lc.contains("for xml") || lc.contains("for json")) {
return false;
}

return (c == 's' || c == 'S') && sql.toLowerCase(Locale.ENGLISH).startsWith("select");
char c = sql.charAt(0);
return (c == 's' || c == 'S') && lc.startsWith("select");
}

}
2 changes: 1 addition & 1 deletion src/test/java/io/r2dbc/mssql/JsonIntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class JsonIntegrationTests extends IntegrationTestSupport {
@Test
void shouldExecuteForJsonSimple() {

connection.createStatement("select 1 as a for json path").fetchSize(0).execute()
connection.createStatement("select 1 as a for json path").execute()
.flatMap(result -> result.map((row, rowMetadata) -> row.get(0)))
.as(StepVerifier::create)
.expectNext("[{\"a\":1}]")
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/r2dbc/mssql/XmlIntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class XmlIntegrationTests extends IntegrationTestSupport {
@Test
void shouldExecuteForXmlSimple() {

connection.createStatement("select 1 as a for xml path").fetchSize(0).execute()
connection.createStatement("select 1 as a for xml path").execute()
.flatMap(result -> result.map((row, rowMetadata) -> row.get(0)))
.as(StepVerifier::create)
.expectNext("<row><a>1</a></row>")
Expand Down

0 comments on commit 43a77a7

Please sign in to comment.