What`s the best way to simulate Oracle Autonomous Transactions on SQLA?
I`m think publishing an webservice on database and create a stored funcion/procedure to consume it.
That`s the better option?
In this case I think that my solution (publish and consume webservices in database) is the best option.
answered 02 Dec '09, 11:31
There is no direct way of doing an autonomous transaction in SQLAnywhere.
You can get close to the same thing by triggering an event that will then perform the transaction.
Then you can add an error message to the log at any time by using:
Some things to note - the size of the parameters passed to the trigger is limited by the database page size. If you need to pass larger pieces of information, then it would be best to create a global temporary table non transactional shared by all and insert the data into this table and pass an "id" of the newly inserted row to the event - the event can then pull the data out of the temp table and do what it needs with it.
Your second requirement - waiting for the transaction to complete before proceeding is a bit more difficult. One method, but not really a decent one (for several reasons), would be to poll the above mentioned global temp table to wait for the row to be deleted and have the event delete the row once it has processed it.
A perhaps better method would be to use
To expand on what Mark said... when an event is executed (triggered), it gets a separate connection, which is why it can commit separately. It also means the event runs asynchronously, unlike a procedure call which runs synchronously. In other words, events run in "fire and forget" mode.
Like Stan Lee said, with great power there must also come — great responsibility! Events are wonderful things. Manually-executed events (as opposed to regularly scheduled ones) are even more wonderful.
The great power is "commits separately". The great responsibility is solving the "bit more difficult" problem of which Mark speaks. I can personally testify that the effort is worth it... I have developed a commercial multi-threaded application which runs entirely inside SQL Anywhere, based on both scheduled and manually-executed events: the Foxhound database monitor. (that's not intended as a pitch for Foxhound, but for SQL Anywhere, without which I would have been floundering in C ten years from now)
answered 11 Nov '09, 09:04
If your autonomous transaction is independent from the calling transaction, a manually triggered event would suffice.
answered 10 Nov '09, 14:54
Just to add a v17 feature to that real old question:
Based on Mark's excellent suggestion of a separate event connection, with v17 you could use a semaphore object to synchronize the current connection and the event connection, say something like the following in the current connection:
and within the event handler, you would finally call
That will then resume the waiting connection.
(Note, in contrast to a synchronization via WAITFOR AFTER MESSAGE BREAK / MESSAGE ... TO CONNECTION, you cannot exchange state information here, but you could also use a global temp table shared by all or the like to do so.)
answered 23 Nov '15, 16:09