[
https://issues.apache.org/jira/browse/IGNITE-22546?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Maksim Myskov reassigned IGNITE-22546:
--------------------------------------
Assignee: Maksim Myskov
> Improve SQL script results processing in CLI
> --------------------------------------------
>
> Key: IGNITE-22546
> URL: https://issues.apache.org/jira/browse/IGNITE-22546
> Project: Ignite
> Issue Type: Improvement
> Components: cli
> Reporter: Pavel Pereslegin
> Assignee: Maksim Myskov
> Priority: Major
> Labels: ignite-3, ignite-3-cli-tool
>
> {{SqlManager#execute}} does not process all the results of script execution.
> {code:java}
> try (Statement statement = connection.createStatement()) {
> if (statement.execute(sql)) {
> ResultSet resultSet = statement.getResultSet();
> return new SqlQueryResult(Table.fromResultSet(resultSet));
> }
> int updateCount = statement.getUpdateCount();
> return new SqlQueryResult(updateCount >= 0 ? "Updated " +
> updateCount + " rows." : "OK!");
> }
> {code}
> Here we read only the result of executing the first statement. But JDBC
> supports the ability to read the execution results of all statements.
> Example:
> {code:java}
> do {
> System.out.println("---");
> if (stmt.getUpdateCount() != -1) {
> System.out.println("update count: " + stmt.getUpdateCount());
> continue;
> }
> try (ResultSet rs = stmt.getResultSet()) {
> while (rs.next()) {
> List<Object> row = new ArrayList<>();
> for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
> row.add(rs.getObject(i + 1));
> }
> System.out.println("row: " + row);
> }
> }
> } while (stmt.getMoreResults() || stmt.getUpdateCount() != -1);
> {code}
> I suggest to improve script processing in {{SqlManager#execute}}.
> I'm not sure what to do with the result sets, but beware that current
> "resultSet" will be closed when {{getMoreResults()}} is called (AI3 JDBC
> implementation limitation).
> At least, it's worth returning the correct number of updates for the entire
> script (but again I'm not sure if it should be one total value or multiple
> values for each statement).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)