Prepared statement parameter validation could query the tuple with the appropriate type
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
@aguibert can you have a look at the feasibility on the DB2 side ?
This PR provides the implementation for PostgreSQL https://github.com/eclipse-vertx/vertx-sql-client/pull/771
@tsegismont can you make sure this works for MSSQL ? @mswatosh can you have a look at this issue for DB2 ?
@vietj this isn't possible for MSSQL (we don't get a description of the parameters)
I believe we can close this issue