Subject Re: [IBO] Re: Newbie transaction questions
Author Joe Martinez
At 08:35 AM 12/11/2002 +1100, you wrote:
>At 08:42 PM 10-12-02 +0000, you wrote:
> > >
> > > Can both inserts and commits generate Key Violations (depending on
> >the situation),
> > > or is it only commits?
>
>You shouldn't be thinking of "an insert causing a key violation". An
>insert is a client-side operation. The server doesn't know about it until
>the client actually posts an INSERT statement to the server.

Ok. I guess I wasn't as clear as I could have been. By "inserts", I
didn't mean an Insert() on a client dataset. I meant posting an SQL INSERT
command to the server.

>You need to understand what you are doing. When you do the Execute, the
>"data" that are sent to the server are just a statement, no different to
>what happens when the work from calls by the dataset to Insert, Edit or
>Delete occur. Your statement is posted, awaiting a call from the client to
>commit or roll back.

Ok. Thank you for your great explanations. Let me make sure I understand
this. First, you call StartTransaction() on the TIB_Transaction
object. This in turn starts a transaction on the server. From there,
there are two ways to do an insert. One is on a dataset, doing an
Insert(), setting the fields, and then calling Post(). The Insert(), and
field setting commands don't send anything to the server. The Post()
method is what triggers the SQL command to be generated and posted to the
server. The other method is to set the SQL directly (such as the SQL
property of TIB_SQL), and calling Execute(). This also posts the SQL
command to the server. At this point, the data is not yet visible to the
rest of the world. Finally, you commit the transaction, and that makes the
change permanent and visible to the rest of the world.

Now, assuming that I have all that correct, and am now using the correct
terminology, let me ask my questions:

1) Consider the following sequence of events:
Client A starts a transaction.
Client B starts a transaction.
Client A posts an INSERT statement, using key 'ABCD'
Client B posts an INSERT statement, using key 'ABCD'
Client A commits it's transaction.
Client B commits it's transaction.

At which point does the Key Violation occur? Is it when Client B posts
it's INSERT statement, or when it commits it's transaction?

2) Now, consider this slightly different sequents of events:
Client A starts a transaction.
Client B starts a transaction.
Client A posts an INSERT statement, using key 'ABCD'
Client A commits it's transaction.
Client B posts an INSERT statement, using key 'ABCD'
Client B commits it's transaction.

In this case, does the Key Violation occur when Client B posts it's INSERT
statement, or it not happen until it commits it's transaction?

3) Final case:
Client A starts a transaction.
Client A posts an INSERT statement, using key 'ABCD'
Client A commits it's transaction.
Client B starts a transaction.
Client B posts an INSERT statement, using key 'ABCD'
Client B commits it's transaction.

Same question as before.

Thanks,
Joe