Skip to content

Commit efe67fe

Browse files
committed
Ignore trailing semicolon in extended statement check.
We now no longer reject statements with a single trailing semicolon. [resolves pgjdbc#439] Signed-off-by: Mark Paluch <[email protected]>
1 parent c82e8a7 commit efe67fe

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/main/java/io/r2dbc/postgresql/ExtendedQueryPostgresqlStatement.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ public String toString() {
157157
static boolean supports(String sql) {
158158
Assert.requireNonNull(sql, "sql must not be null");
159159

160-
return !sql.trim().isEmpty() && !sql.contains(";") && sql.contains("$1");
160+
int semicolon = sql.indexOf(';');
161+
162+
return !sql.trim().isEmpty() && (semicolon == -1 || sql.trim().length() - 1 == semicolon) && sql.contains("$1");
161163
}
162164

163165
Binding getCurrentBinding() {

src/test/java/io/r2dbc/postgresql/ExtendedQueryPostgresqlStatementUnitTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ void supportsQueryEmpty() {
408408
@Test
409409
void supportsSemicolon() {
410410
assertThat(ExtendedQueryPostgresqlStatement.supports("test-query-1; test-query-2")).isFalse();
411+
assertThat(ExtendedQueryPostgresqlStatement.supports("test-query-1; test-query-2;")).isFalse();
412+
assertThat(ExtendedQueryPostgresqlStatement.supports("test-query-1; test-query-2 with $1;")).isFalse();
413+
assertThat(ExtendedQueryPostgresqlStatement.supports("test-query-1 with $1; ")).isTrue();
414+
assertThat(ExtendedQueryPostgresqlStatement.supports("test-query-1 with $1;")).isTrue();
411415
}
412416

413417
@Test

0 commit comments

Comments
 (0)