如何在UIB中使用Firebird事务隔离级别?

时间:2013-02-19 08:32:26

标签: delphi firebird uib

根据documents,Firebird中有四个事务隔离级别。但是,据我所知,uib库(TUIBTransaction)中没有明确的隔离级别选择,而是事务的一堆选项。我该怎么用?某处有文件吗?

1 个答案:

答案 0 :(得分:1)

这些选项会改变隔离级别。正如@Arioch在其简短评论中所说,您可以更改隔离级别,更改Options类型的属性TTransParams。这是一组TTransParam,如下所示。

 // Transaction parameters
TTransParam = (
{ prevents a transaction from accessing tables if they are written to by
other transactions.}
tpConsistency,
{ allows concurrent transactions to read and write shared data. }
tpConcurrency,
{ Concurrent, shared access of a specified table among all transactions. }
{$IFNDEF FB_21UP}
tpShared,
{ Concurrent, restricted access of a specified table. }
tpProtected,
tpExclusive,
{$ENDIF}
{ Specifies that the transaction is to wait until the conflicting resource
is released before retrying an operation [Default]. }
tpWait,
{ Specifies that the transaction is not to wait for the resource to be
released, but instead, should return an update conflict error immediately. }
tpNowait,
{ Read-only access mode that allows a transaction only to select data from tables. }
tpRead,
{ Read-write access mode of that allows a transaction to select, insert,
update, and delete table data [Default]. }
tpWrite,
{ Read-only access of a specified table. Use in conjunction with tpShared,
tpProtected, and tpExclusive to establish the lock option. }
tpLockRead,
{ Read-write access of a specified table. Use in conjunction with tpShared,
tpProtected, and tpExclusive to establish the lock option [Default]. }
tpLockWrite,
tpVerbTime,
tpCommitTime,
tpIgnoreLimbo,
{ Unlike a concurrency transaction, a read committed transaction sees changes
made and committed by transactions that were active after this transaction started. }
tpReadCommitted,
tpAutoCommit,
{ Enables an tpReadCommitted transaction to read only the latest committed
version of a record. }
tpRecVersion,
tpNoRecVersion,
tpRestartRequests,
tpNoAutoUndo
{$IFDEF FB20_UP}
,tpLockTimeout
{$ENDIF}
); 

由于Interbase 6.0代码“opensourced”,API的文档没有太大变化。因此,如果您想要解释其中任何一个,您正在查找的文档都在Interbase手册中。

你可以在这里http://www.firebirdsql.org/en/reference-manuals/

下面我引用Ann Harrison的link快速解释一下常用的选项:

  

isc_tpb_consistency可能会导致性能问题,因为它锁定表并可能排除并发访问。   isc_tpb_concurrency是Firebird的设计中心。读者没有   块编写者,编写者不会阻止读者,并且两者都得到一致   查看数据库。

     

isc_tpb_read_committed + isc_tpb_rec_version + isc_tbp_read_only give   结果不一致,偶尔会在blob上产生错误   read *,但与其他模式不同,它不会阻止垃圾收集   对于长时间运行的读取事务而言,这是一个很好的模式   得到“正确”的答案。

     

isc_tpb_read_committeed + isc_tpb_rec_version具有相同的性能   作为isc_tpb_concurrency,但获得不一致的结果 - 相同的查询   在同一事务中运行两次可能会返回不同的行。

     

isc_tpb_read_committed + isc_tpb_no_rec_version + isc_tpb_wait是   比其他模式慢,因为它会等待更改   承诺而不是阅读最新的承诺版本。像所有人一样   isc_tpb_read_committed的变体,它不会产生一致   结果

     

isc_tpb_read_committed + isc_tpb_no_rec_version + isc_tpb_no_wait   每次读者都会产生大量的死锁错误   遇到正在更改的记录,它会返回错误。

注意:我希望您可以看到,除了参数名称不同之外,如果删除“isc_tpb_”部分并不难理解。