Jiři,

I've already had to go through the pain of getting the IResultSet and IStatement interface to work when developing the Firebird Pascal API that is distributed with IBX. The strategy that I found that works is:

1. A cursor (IResultSet) is best disposed of with "close" unless the transaction is no longer active when "release" will do.

2. A statement (IStatement) is disposed of with a "release".

3. A transaction (ITransaction) is disposed of with a "release"

4. An attachment (IAttachment) is disposed of with a "detach".

In all cases, you should null the pointer to the interface after disposing of it.

The Firebird Pascal API is object oriented and more than one copy of an object can reference the same underlying Firebird interface, hence it always uses reference counter interfaces to dispose of objects.

Regards

Tony Whyman

MWA

On 05/12/2019 09:01, Jiří Činčura wrote:
Maybe better to show some code (simplified). Expecting the free and release to 
have separate responsibilities I wrote initially (the variables with underscore 
are class fields). The Execute is called at some point and Free is called 
either after the IExternalFunctionImpl finished executing or in 
IExternalResultSetImpl::dispose (because that's the only place I'm aware of I 
know no more fetching will occur and the fetching might end up in the middle 
not reading all the results (otherwise I would know it because fetchNext would 
return != IStatus::RESULT_OK).

void Execute(const char* stmt)
{
        auto status = ThrowStatusWrapper(_context->getMaster()->getStatus());
        _attachment = _context->getAttachment(&status);
        _transaction = _context->getTransaction(&status);
        _statement = _attachment->prepare(&status, _transaction, 0, stmt, 
SQL_DIALECT_CURRENT, 0);
        _cursor = _statement->openCursor(&status, _transaction, nullptr, 
nullptr, outMetadata, 0);
        _msg = new unsigned char[outMetadata->getMessageLength(&status)];
        // other method does the fetchNext
}

void Free()
{
        _cursor->close(&status);
        _statement->free(&status);

        delete _msg;
        _msg = nullptr;
        _cursor->release();
        _cursor = nullptr;
        _statement->release();
        _statement = nullptr;
        _transaction->release();
        _transaction = nullptr;
        _attachment->release();
        _attachment = nullptr;
}



Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to