vert-x3 / vertx-mysql-postgresql-client

This client is deprecated - use instead
https://github.com/eclipse-vertx/vertx-sql-client
Apache License 2.0
117 stars 59 forks source link

AsyncSQLConnectionImpl will pending, When exceute wrong sql ,and thow exception. #116

Closed xiaobaojiang closed 6 years ago

xiaobaojiang commented 6 years ago

String sql = " select * from users where uid = ? and name = ? " ;
JsonArray params = new JsonArray().add(1) ;  //  just one paramter.
conn.queryWithParams( sql, params, res-> {} );
  1. If params length can't match sql ? placeholder , the postgres-async drive will throw new InsufficientParametersException(holder.paramsCount, values), and conn.queryWithParams() can't catch the exception , it will always pending. and if postgresql-async drive throw other exception , it will alse peding .

  2. I suggest use Future instead of callback way , because Future can avoid the unexpected exception

    Future.<Void>future(future -> beginTransactionIfNeeded(future.completer()))
                .compose(success -> {
                    Future<ResultSet> future1 = Future.future();
                    final scala.concurrent.Future<QueryResult> future = connection.sendPreparedStatement(sql,
                            ScalaUtils.toScalaList(params.getList()));
                    future.onComplete(ScalaUtils.toFunction1(handleAsyncQueryResultToResultSet(future1)), executionContext);
                    return future1;
                })
                .setHandler(res -> {
                    handler.handle(res);
                });
    
        return this;