vertx-jdbc-client3.5.2 postgresql:sql更新原因“未预期会返回结果”

时间:2018-07-03 07:51:10

标签: vert.x

在vertx-jdbc-client 3.5.0中,sql“ DELETE FROM user;INSERT INTO user...”正常。更新到vertx-jdbc-cient 3.5.2之后,sql失败,并显示以下错误: io.vertx.core.VertxException: org.postgresql.util.PSQLException: A result was returned when none was expected。通过调试,我发现SQL已自动更改为DELETE FROM user RETURNING *;INSERT INTO user ...,然后RETURNING *导致更新错误。

我找到了原因:在vert-jdbc-client 3.5.0中。

class JDBCConnectionImpl implements SQLConnection {
...
  private SQLOptions options;

}

在vert-jdbc-client 3.5.2中:

class JDBCConnectionImpl implements SQLConnection {
    ...
    private SQLOptions options = new SQLOptions().setAutoGeneratedKeys(true);
}

然后casue

public class Parser {
...
  private static boolean addReturning(StringBuilder nativeSql, SqlCommandType currentCommandType,
      String[] returningColumnNames, boolean isReturningPresent) throws SQLException {
    if (isReturningPresent || returningColumnNames.length == 0) {
      return false;
    }
    if (currentCommandType != SqlCommandType.INSERT
        && currentCommandType != SqlCommandType.UPDATE
        && currentCommandType != SqlCommandType.DELETE) {
      return false;
    }

    nativeSql.append("\nRETURNING ");
...
}

我应该修改SQL代码还是设置JDBC客户端?谁能给我一个建议?

1 个答案:

答案 0 :(得分:0)

我只是发现这不是问题,因为当我编写SQLConnection sqlConnection = ...; sqlConnection.setOptions(null);时,旧的sql更新就可以了。所以我认为这是一个更改。