felipecrv commented on issue #2694:
URL: https://github.com/apache/arrow-adbc/issues/2694#issuecomment-2794524780
> FWIW, I recently changed this a bit for the Postgres driver (previously
the connection had to outlive the reader, now that's OK but the reader will
error if used after the connection is torn down)
@lidavidm I imagined that is how all drivers were supposed to work since
they are handing out these pointers through the FFI -- connection keeps weak
ref to database, statement and record batch readers keeps weak refs to
connection. And whenever a strong reference can't be established, we get an
error from the reader.
In C++ terms:
```cpp
struct Statement {
std::weak_ptr<int> connection;
};
void next_batch(Statement &stmt) {
// we have to make a copy of shared pointer before usage:
if (auto conn = stmt.connection.lock())
...read record batch with resources in the connection...
else
...error...
}
```
And if that's the case should we force the Rust code to enforce this
statically? I'm not opposed to this, but it could be unnecessarily restrictive.
----
Note that `Connection::get_objects()` is just one example.
`Statement::execute()` -- Shouldn't discarding the Statement object be fine?
`Connection` has a lot more methods returning `impl RecordBatchReader` and
receiving many `&` arguments other than the `&self`.
@mbrobbel if you cherry-pick my first commit in the draft PR, you can
experiment with different solutions. My goal really is being able to return a
boxed `RecordBatchReader` that doesn't have to carry the tiny `&str`s that are
passed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]