r2dbc / r2dbc-spi

Service Provider Interface for R2DBC Implementations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Should extraneous `add` calls on `Statement` demand an error?

gregturn opened this issue · comments

TestKit currently verifies that if you add an extraneous add to your Statement, an Error must be thrown.

@Test
default void prepareStatementWithTrailingAddShouldFail() {
    Flux.usingWhen(getConnectionFactory().create(),
            connection -> {
                Statement statement = connection.createStatement(expand(TestStatement.INSERT_VALUE_PLACEHOLDER, getPlaceholder(0)));

                bind(statement, getIdentifier(0), 0).add(); // <----- this

                return Flux.from(statement
                        .execute())
                    .flatMap(this::extractRowsUpdated).then();
            },
            Connection::close)
        .as(StepVerifier::create)
        .verifyError();
}

For r2dbc-h2, this results in a failure because in the code, add simply switches the current binding pointer to null. We don't actually create some empty, unpopulated record to track through.

To trigger the behavior up above, we would need to do something less elegant and stuff an empty unpopulated Binding record and then detect if before execution.

I see three options:

  1. Uphold this as an SPI behavior all data stores must implement and we go through with pushing an empty but unpopulated binding into our code as mentioned earlier.
  2. Drop this test scenario and let each module pick it up if need be. Perhaps some modules act this way and some do not.
  3. r2dbc-h2 could simply override this test method and switch to verifyComplete() so we don't have to alter our code but still have passing tests, documenting our behavior.

Thoughts? I'm leery of having different behavior between modules. But I also don't like forcing unnecessary data through the system.

For r2dbc-h2, this results in a failure because in the code, add simply switches the current binding pointer to null. We don't actually create some empty, unpopulated record to track through.

That is exactly what the test catches and the motivation to put this rule in place.