Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MariaDB driver behaves differently to other implementation with regards to batch inserts #8

Closed
graemerocher opened this issue Nov 6, 2020 · 1 comment

Comments

@graemerocher
Copy link

graemerocher commented Nov 6, 2020

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:

micronaut-projects/micronaut-r2dbc@6c5ee41

@rusher
Copy link
Collaborator

rusher commented Nov 24, 2020

Thanks for report.
This will be corrected in next version.

@rusher rusher closed this as completed Nov 24, 2020
This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants