Thanks, Zvoni, I don't really know, as I actually never used odbc, but I use something very similar to method I described with FBConnection. I'll say more about what I do.
First, to be complete, it should be added to my previous post that the thread2 should obtain the transaction (or connection) handle and pass it to main thread (in a synchronized procedure, of course) before it starts the query execution, so that the main thread can use it to kill the transaction (connection) if needed.
As I said, I don't know much about ODBC, but I do use the very similar method with FBConnection, where I kill the query by executing in main thread (
see here)
DELETE FROM mon$attachments WHERE mon$attachment_id = <connection_id>
.
Of course, <connection_id> is replaced with actual value, which had been got earlier from thread2, when the thread2 started, with 'select current_connection from rdb$database'.
Note that it kills the connection, not just transaction (ie. it needs separate connection component in the thread).
Perhaps it might be done by
killing the statement, but I don't know how would I get the statement id before the statement starts (and when the statement starts, the thread is blocked).
Firebird documentation does not give the similar way to kill the transaction, as it seems you can only either kill a statement or whole connection.
This works quite well for me, and in my use case, it is quite okay to kill the connection, it's just that thread has to create and use it's own connection component (not just transaction, which is surely needed, as transaction is not thread safe), so I didn't bother to find the way to kill just the particular statement or the transaction.