Skip to content

Commit

Permalink
[R2DBC-85] adding hint in order to execute text command when useServe…
Browse files Browse the repository at this point in the history
…rPrepStmts option is set
  • Loading branch information
rusher committed Mar 2, 2023
1 parent e69e3f6 commit 3b6ef05
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/mariadb/r2dbc/MariadbConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public MariadbStatement createStatement(String sql) {
throw new IllegalArgumentException("Statement cannot be empty.");
}

if (this.configuration.useServerPrepStmts() || sql.contains("call")) {
if ((this.configuration.useServerPrepStmts() || sql.contains("call")) && !sql.startsWith("/*text*/")) {
return new MariadbServerParameterizedQueryStatement(this.client, sql, this.configuration);
}
return new MariadbClientParameterizedQueryStatement(this.client, sql, this.configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.junit.jupiter.api.*;
import org.mariadb.r2dbc.BaseConnectionTest;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;

public class ProcedureResultsetTest extends BaseConnectionTest {

Expand All @@ -31,11 +32,19 @@ public static void before2() {
+ "END")
.execute()
.blockLast();
sharedConn
.createStatement(
"CREATE PROCEDURE no_out_proc (IN t1 INT, IN t2 INT) BEGIN \n"
+ "DO t1 + t2;\n"
+ "END")
.execute()
.blockLast();
}

@AfterAll
public static void dropAll() {
sharedConn.createStatement("DROP PROCEDURE IF EXISTS basic_proc").execute().blockLast();
sharedConn.createStatement("DROP PROCEDURE IF EXISTS no_out_proc").execute().blockLast();
}

@Test
Expand Down Expand Up @@ -101,5 +110,58 @@ void outputParameter() {
Assertions.assertEquals("test", l.get(1).get(4));
}
Assertions.assertEquals(LocalDateTime.parse("2003-12-31T12:00:00"), l.get(1).get(3));

List<List<Object>> l2 =
sharedConn
.createStatement("/*text*/ call basic_proc(?,?,?,?,?,?,?)")
.bind(0, 2)
.bind(1, Parameters.inOut(2))
.bind(2, Parameters.out(R2dbcType.INTEGER))
.bind(3, 10)
.bind(4, Parameters.out(R2dbcType.VARCHAR))
.bind(5, Parameters.out(R2dbcType.TIMESTAMP))
.bind(6, Parameters.out(R2dbcType.VARCHAR))
.execute()
.flatMap(
r ->
Flux.from(
r.filter(Result.OutSegment.class::isInstance)
.flatMap(
seg -> {
return Flux.just(
((Result.OutSegment) seg).outParameters().get(0),
((Result.OutSegment) seg).outParameters().get(1),
((Result.OutSegment) seg).outParameters().get(2),
((Result.OutSegment) seg).outParameters().get(3),
((Result.OutSegment) seg).outParameters().get(4));
}))
.collectList())
.collectList()
.block();

Assertions.assertEquals(1, l2.size());
}
@Test
void inParameter() {
Assumptions.assumeFalse(isXpand());
sharedConn
.createStatement("call no_out_proc(?,?)")
.bind(0, 2)
.bind(1, 10)
.execute()
.flatMap(it -> it.getRowsUpdated())
.as(StepVerifier::create)
.expectNext(0L)
.verifyComplete();
sharedConn
.createStatement("/*text*/ call no_out_proc(?,?)")
.bind(0, 2)
.bind(1, 10)
.execute()
.flatMap(it -> it.getRowsUpdated())
.as(StepVerifier::create)
.expectNext(0L)
.verifyComplete();
}

}

0 comments on commit 3b6ef05

Please sign in to comment.