vertx-sql-client icon indicating copy to clipboard operation
vertx-sql-client copied to clipboard

Prepared statement parameter validation could query the tuple with the appropriate type

Open vietj opened this issue 5 years ago • 3 comments

The parameter validation for prepared statement execution is achieved by each codec when values are encoded by the prepared statement execution: io.vertx.sqlclient.impl.PreparedStatement#prepare method.

For a given tuple index, the current implementation gets the tuple value at the specific index and then check the type is correct, performing some transformation on the fly (e.g enum values are converted to string).

When the prepared statement has a correct description of the parameters, it can call the most appropriate methods on the Tuple interface that will perform the conversion, e.g internally

// Instead of
return column[idx].type.cast(tuple.getValue(idx));

// We do
if (column[idx].type == Integer.class) {
  return tuple.getInteger(idx);
}

This would enable SQL templates to wrap a JsonObject with a tuple that would be able to perform the conversion, e.g a string could be converted to a date.

Implementations

  • PostgreSQL: possible
  • MySQL: not possible because parameter description provided by MySQL is not correct
  • MSSQL: might work after changing the execution flow stated in https://github.com/eclipse-vertx/vertx-sql-client/issues/546
  • DB2: ?

This draft PR provides support for PostgreSQL and the JSON tuple prototype https://github.com/eclipse-vertx/vertx-sql-client/pull/771

vietj avatar Sep 18 '20 06:09 vietj

@aguibert can you have a look at the feasibility on the DB2 side ?

vietj avatar Sep 22 '20 15:09 vietj

This PR provides the implementation for PostgreSQL https://github.com/eclipse-vertx/vertx-sql-client/pull/771

vietj avatar Sep 24 '20 08:09 vietj

@tsegismont can you make sure this works for MSSQL ? @mswatosh can you have a look at this issue for DB2 ?

vietj avatar Jun 03 '21 09:06 vietj

@vietj this isn't possible for MSSQL (we don't get a description of the parameters)

I believe we can close this issue

tsegismont avatar Feb 03 '23 17:02 tsegismont