[R2DBC-11] Batching on statement use parameters not added Created: 2020-11-24  Updated: 2020-11-24  Resolved: 2020-11-24

Status: Closed
Project: MariaDB Connector/R2DBC
Component/s: batch
Affects Version/s: 0.8.4-rc
Fix Version/s: 1.0.0

Type: Bug Priority: Major
Reporter: Diego Dupin Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: 1h
Time Spent: 0.25d
Original Estimate: 3h


 Description   

from #8

The MariaDB implementation of batch inserts with prepared statements currently requires at least one statement to not be part of a batch when doing batch inserts with prepared statements otherwise an error such as the following occurs:

java.lang.IllegalArgumentException: Parameter at position 0 is not set
	at org.mariadb.r2dbc.MariadbClientParameterizedQueryStatement.execute(MariadbClientParameterizedQueryStatement.java:132)
	at org.mariadb.r2dbc.MariadbClientParameterizedQueryStatement.execute(MariadbClientParameterizedQueryStatement.java:34)
	at io.micronaut.data.r2dbc.operations.DefaultR2dbcRepositoryOperations$DefaultR2dbcReactiveRepositoryOperations.lambda$persistAll$18(DefaultR2dbcRepositoryOperations.java:491)
	at

Looking at the validation logic in MariadbClientParameterizedQueryStatement it does this:

 
  public Flux<org.mariadb.r2dbc.api.MariadbResult> execute() {
 
    // valid parameters
    for (int i = 0; i < prepareResult.getParamCount(); i++) {
      if (parameters[i] == null) {
        throw new IllegalArgumentException(String.format("Parameter at position %s is not set", i));
      }
    }
 
    if (batchingParameters == null) {

If you call add() for the last batch statement then all entries in parameters are null and they exist only in batchParameters. It seems to be that this check should only be executed if batchingParameters == null and the validation check should be moved inside the if statement.

This differs to other implementations whereby you can call add() for each statement and execute them no problem. As a result of this I have to place a MariaDB specific hack into the code I am developing to allow batch inserts to execute across different implementations:


Generated at Thu Feb 08 03:32:01 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.