eclipse-vertx / vertx-sql-client

High performance reactive SQL Client written in Java
Apache License 2.0
894 stars 200 forks source link

Pg Client might convert a query param to NULL if it has the wrong type #1463

Closed tsegismont closed 2 months ago

tsegismont commented 2 months ago

Originally reported in #1281

As an example, if the query has a parameter of type interval, mapped by io.vertx.pgclient.data.Interval, and the user puts a java.time.Duration, then PgClient will set the value to NULL.

It happens here:

https://github.com/eclipse-vertx/vertx-sql-client/blob/cc9803f073f4f7ca7717e97f20d8fdc810ff32ab/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/PgParamDesc.java#L53-L62

We would expect the client to reject the query using a message generated by buildWhenArgumentsTypeNotMatched.

But the INTERVAL data type is defined without a type extractor:

INTERVAL(1186, true, Interval.class, JDBCType.DATE),

So the client invokes values.get(paramDataType.encodingType, i);

And there the returned value is null because Interval is not assignable from Duration:

https://github.com/eclipse-vertx/vertx-sql-client/blob/2de7f0dd3b1719c5ab5523f85cc7507c9ec1ac1d/vertx-sql-client/src/main/java/io/vertx/sqlclient/Tuple.java#L1716-L1719

tsegismont commented 2 months ago

Fixed by #1464