Board index » delphi » "Prepared" and Transaction scope

"Prepared" and Transaction scope

Can someone clarify this apparent behaviour with prepared ibx datasets: with
an explicit transaction and explicit prepare, TIBQuery will remain prepared
after a Commit, but TIBDataSet will not (it seems).

It makes sense (to me) that Prepare requires db access and therefore an
active TIBTransaction, but that UnPrepare might not (coz its just cleaing
up)...so its reasonable that an explicit prepare persists outside the scope
of the transaction (ie after a commit). This behaviour might be useful for
an often-used form whose datasets can be prepared ONCE on creation (and
un-prepared ONCE when freed), but which does not carry an open transaction
indefintely when not in use...(ie always Commit when form hidden)...

Would this be bad practice or invalid reasoning?
Is there a good reason why TIBDataSet will not remain prepared after a
commit?
Or am I missing something important?

Thanks.

--
Brent Rose
brentr...@clear.net.nz

 

Re:"Prepared" and Transaction scope


Quote
Brent Rose wrote:

> Can someone clarify this apparent behaviour with prepared ibx datasets: with
> an explicit transaction and explicit prepare, TIBQuery will remain prepared
> after a Commit, but TIBDataSet will not (it seems).

IBQuery will not remain prepared.  You never need to explicitly prepare IBX.
IBX will unprepare when it needs to irregardless if it prepared or you prepared
it.  DoBeforeTransactionEnd is what unprepares a query when the transaction is
ended.  This is done at the TIBCustomDataset and does not get overridden by
IBQuery.

Quote

> It makes sense (to me) that Prepare requires db access and therefore an
> active TIBTransaction, but that UnPrepare might not (coz its just cleaing
> up)...so its reasonable that an explicit prepare persists outside the scope
> of the transaction (ie after a commit).

Wrong.  Part of what happens on a prepare is the DB creates a plan based on the
current transaction's view of the metadata.  Once that transaction view is ended
this is no longer a valid metadata view so needs to be unprepared.  IBSQL
actually does not unprepare automatically.  I can break this behavior with 4 or
5 lines of code (it isn't that hard if you think in terms of what it would take
to invalidate a plan).  Since people have not hit this problem with IBSQL I have
not changed the behavior, but technically it is a bug.

Quote
> This behaviour might be useful for
> an often-used form whose datasets can be prepared ONCE on creation (and
> un-prepared ONCE when freed), but which does not carry an open transaction
> indefintely when not in use...(ie always Commit when form hidden)...

> Would this be bad practice or invalid reasoning?
> Is there a good reason why TIBDataSet will not remain prepared after a
> commit?

Yes, IB does things like Plans based on your current transaction.  Metadata
changes (like deactivating an index) will cause the plan to be invalid if you
end your transaction and get a new one that sees the meta data changes.

Quote
> Or am I missing something important?

> Thanks.

> --
> Brent Rose
> brentr...@clear.net.nz

--
Jeff Overcash (TeamB)
      (Please do not email me directly unless  asked. Thank You)
This sad little lizard told me that he was a brontosaurus on his mother's
side.  I did not laugh; people who boast of ancestry often have little else
to sustain them.  Humoring them costs nothing and ads to happiness in
a world in which happiness is in short supply.   (RAH)

Re:"Prepared" and Transaction scope


Thanks for this insight Jeff - just to confirm, please:

Firstly, there is NEVER any real advantage in attending explicitly to
dataset Prepare/UnPrepare with ibx??

Secondly, the fact that TIBQuery reports "Prepared = True" after a commit is
not accurate or is simply not relevant???

--
Brent Rose
brentr...@clear.net.nz

Re:"Prepared" and Transaction scope


Quote
Brent Rose wrote:

> Thanks for this insight Jeff - just to confirm, please:

> Firstly, there is NEVER any real advantage in attending explicitly to
> dataset Prepare/UnPrepare with ibx??

True.  Unlike the BDE which when it auto prepares will unprepare when the the
dataset is closed (which is why you explicitly prepare for the BDE)  IBX
prepares once and leaves it prepared until either a) you change the driving SQL
or the transaction ends.

Quote

> Secondly, the fact that TIBQuery reports "Prepared = True" after a commit is
> not accurate or is simply not relevant???

It is inaccurate.  I will look at why later.

--
Jeff Overcash (TeamB)
      (Please do not email me directly unless  asked. Thank You)
This sad little lizard told me that he was a brontosaurus on his mother's
side.  I did not laugh; people who boast of ancestry often have little else
to sustain them.  Humoring them costs nothing and ads to happiness in
a world in which happiness is in short supply.   (RAH)

Re:"Prepared" and Transaction scope


Ah - more BDE hangovers! You live & you learn.

...guess I'll be cleaning up some IB prepare/unprepare code!!

Thanks again, Jeff.

--
Brent Rose
brentr...@clear.net.nz

Other Threads