SOCI / soci

Official repository of the SOCI - The C++ Database Access Library
http://soci.sourceforge.net/
Boost Software License 1.0
1.37k stars 472 forks source link

Fix `row::move_as` behavior breaking reusability #1145

Open Krzmbrzl opened 2 months ago

Krzmbrzl commented 2 months ago

For the time being, this is merely a sketch of how I think the fix has to work. The current implementation fails at the unavailability of a session object at the row scope...

Once this is finished, this PR fixes #1144

Krzmbrzl commented 2 months ago

@avpalienko could you debug where the SegFault for Oracle is coming from? You seem to have good access to an Oracle installation, whereas for me it is always super tedious to get something to work.

avpalienko commented 2 months ago

@avpalienko could you debug where the SegFault for Oracle is coming from? You seem to have good access to an Oracle installation, whereas for me it is always super tedious to get something to work.

I've debugged on windows and have no segfault. But test fails:


BLOB Blob binding move_as

D:\CMA\Dev\SOCI\soci_githab\tests\common-tests.h(6784) ...............................................................................

D:\CMA\Dev\SOCI\soci_githab\tests\common-tests.h(6784): FAILED: {Unknown expression after the reported line} due to unexpected exception with message: soci error: Invalid handle while fetching data from "select b from soci_test where id=:id" with :1=42.

=============================================================================== test cases: 2 | 1 passed | 1 failed assertions: 162 | 161 passed | 1 failed

I think it's a result of the move_as. Lob locator binds to the statement in define_by_pos():

bbe->reset(); ociData_ = bbe->get_lob_locator();

and then it initialized by OCIDefineByPos(). But in row::move_as() we call dtor ~oracle_blob_backend() with OCIDescriptorFree inside. On the next fetch in the post_fetch we call bbe->set_lob_locator(). Inside it we set locator in the old released value and call OCILobIsOpen which returns OCI_INVALID_HANDLE