Nina
Nina

Reputation: 63

R2DBC DatabaseClient parameter binding

I am unable to bind parameters to my query. The function looks like this:

override fun findVenueById(id: Long): Mono<Venue> {
    val extended = query + "WHERE v.id = :id  "
    return client
        .sql(extended)
        .bind("id", id)
        .map(venueMapper::apply)
        .one()
}

The client: DatabaseClient is injected from this Bean:

@Bean
fun databaseClient(connectionFactory: ConnectionFactory): DatabaseClient {
    return DatabaseClient.builder()
        .connectionFactory(connectionFactory)
        .bindMarkers(BindMarkersFactory.named(":", "", 20))
        .namedParameters(true)
        .build()
}

When I use .bindMarkers with DatabaseClient builder, an exception java.lang.UnsupportedOperationException is thrown with message:

Binding parameters is not supported for the statement 'SELECT v.id AS venue_id ... ... ... WHERE v.id = :0id '

Why is my parameter not supported and why it was renamed to :0id ?

I also tried to omit .bindMarkers from builder, I believe it is supposed to use a default binding strategy, but in this case an exception java.lang.IllegalArgumentException is thrown with message:

Cannot encode parameter of type io.r2dbc.spi.Parameters$InParameter

I went through several examples and discussions on github, but I'm unable to find a solution.

EDIT: I switched to 2 weeks old release org.postgresql:r2dbc-postgresql:1.0.1.RELEASE and now it works.

Upvotes: 3

Views: 1381

Answers (0)

Related Questions