Subject Re: [firebird-support] Other doubts with transactions
Author Martijn Tonies
Hi,

> I'm still experimenting with Firebird in the hope that sooner or later
> I will not need to ask questions any more :-)
>
> My current practice is to use an explicit transaction only when I make
> changes to a table, but I often see that people here speak of
> transactions also for simple select's. Now this is what I do:
>
> 1. Open a table with, for example, a simple 'select * from table'
> 2. start a transaction if I have to modify it
> 3. commit or rollback (hard)
>
> As you can see, I never start a transaction when I simply open the
> query for browsing. Then my questions are:
>
> 1. Do I have to start a transaction also for opening the query?

If you don't, the component set you're using will do this for you.

> 2. If yes, can I start it before the query is open?

Indeed, you should.

> 3. If yes again, a commit or rollback will commit or rollback the
> query opening as well, so I have to open it again, right?

That depends. If you have a caching component, you can view
data without having an actual cursor open on the server. If not,
then yes, committing will close the cursor.

> 4. Do I really need all this, or is the default transaction of the
> connection taking care of the query opening letting me play with my
> explicit transaction only during changes not worrying of opening?

Well, that depends. If you have multiple cursors all using the
default transaction, then when does the default transaction
gets committed?

On the other hand, a read-only, read-committed transaction (I
believe) doesn't matter when it comes to stuck transaction counters.


> 5. If yes for 4., closing the query will commit (or rollback?) the
> default transaction as well, right?

That depends on your component set and settings.

> 6. Are there any special cases when I DO have to explicitly start a
> transaction for a simple query open for browse (no edit)?

See all of the above.

With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com