Skip to content

Conversation

@enebo
Copy link
Member

@enebo enebo commented Jun 6, 2025

This should create less empty result arrays if there are multiple insert/update/deletes.

@enebo
Copy link
Member Author

enebo commented Jun 6, 2025

@seuros Just look this over. I am not sure my second comment is possible using JDBC since if I try to look ahead I got an inconsistent state error. I guess it makes sense that I cannot look at next one until I process resultset of current one.

@seuros
Copy link
Contributor

seuros commented Jun 6, 2025

I just realized we are operating on the driver not the adapter.

If we targeting only ActiveRecord, then this seems enough since AR always execute one SQL statement per exec_query.

if (hasResultSet) {
    try (ResultSet resultSet = statement.getResultSet()) {
        return mapQueryResult(context, connection, resultSet);
    }
} else {
    return newEmptyResult(context);
}

If we want to keep mirroring pg gem

IRubyObject result = newEmptyResult(context);

do {
    if (hasResultSet) {
        try (ResultSet rs = statement.getResultSet()) {
            result = mapQueryResult(context, connection, rs);
        }
    } else {
        result = newEmptyResult(context);
    }

    hasResultSet = statement.getMoreResults();
    updateCount = statement.getUpdateCount();
} while (hasResultSet || updateCount != -1);

return result;

@enebo
Copy link
Member Author

enebo commented Jun 6, 2025

@seuros I think we can mirror pg since we have some minor and unofficial pg support for mini_sql (not sure if it even works any more but it may be worth it to keep it).

@enebo
Copy link
Member Author

enebo commented Jun 6, 2025

@seuros adopted your changes from comment but the original intent is still here result == null so we are not alloc'ing n extra arrays.

@enebo enebo merged commit 3d36773 into master Jun 6, 2025
6 of 12 checks passed
@enebo enebo deleted the topic/only_one_empty branch June 6, 2025 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants