⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transactions.htm

📁 Absolute Database 5.12 src. Absolute Database lets you forget the Borland Database Engine (BDE). Th
💻 HTM
字号:
<html>
<head>
   <title>Transactions</title>
</head>

<!--#include virtual="/inc/header.php"-->


<table width="100%" border="0" cellspacing="0" cellpadding="2" bgcolor="#FFFFFF">
  <tr>
    <td align="left">
      
<span style="font-family:Helvetica,Arial; font-size:12pt; color:#000000"><b>Transactions
<br>
</b></span>
    </td>
    <td align="right">
     <font face="Arial" size="2">
     <a href="lockingandmulti_useraccess.htm">Previous</a>&nbsp;
     <a href="overview.htm">Top</a>&nbsp;
     <a href="restructuringtables.htm">Next</a>
     </font>
    </td>
  </tr>
</table>
<br><br>



<span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><b>
<br>
</b><b>Transaction</b>
<br>

<br>
<span style="font-family:Times New Roman; font-size:12pt; color:#000000">A transaction is a sequence of operations performed as a single logical unit of work. A logical unit of work must exhibit four properties, called the <a href=acid.htm>ACID</a> (Atomicity, Consistency, Isolation, and Durability) properties, to qualify as a transaction.</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>

<br>

<br>
<b>Controlling Transactions
<br>
</b>
<br>
</span><span style="font-family:Times New Roman; font-size:12pt; color:#000000">Applications control transactions mainly by specifying when a transaction starts and ends. This can be specified using either TABSDatabase methods or SQL statements.</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"> An example of code with transaction use:
<br>

<br>
<b>begin</b>
<br>
   <b>with</b> MyABSDatabase <b>do</b>
<br>
      <b>begin</b>
<br>
        StartTransaction;
<br>
        <b>try</b>
<br>
           // Multiple table updates or some other actions
<br>
           { ... }
<br>
           Commit;
<br>
        <b>except</b>
<br>
           Rollback;
<br>
        <b>end;
<br>
      end;</b>
<br>
<b>end;</b>
<br>

<br>
<b>START TRANSACTION</b>
<br>
You can start transactions in Absolute Database through either an </span><span style="font-family:Times New Roman; font-size:12pt; color:#000000">TABSDatabase.<a href=tabsdatabase_starttransaction.htm>StartTransaction</a> call</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"> or the START TRANSACTION statement of Absolute Database SQL. 
<br>

<br>
You can end transactions with either a COMMIT or ROLLBACK statement.
<br>

<br>
<b>COMMIT</b>
<br>
If a transaction is successful, commit it. A COMMIT statement guarantees all of the transaction's modifications are made a permanent part of the database. A COMMIT also frees resources, such as locks, used by the transaction.
<br>
You can commit transaction through either an </span><span style="font-family:Times New Roman; font-size:12pt; color:#000000">TABSDatabase.<a href=tabsdatabase_commit.htm>Commit</a> call</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"> or the COMMIT statement of Absolute Database SQL.
<br>
By default the Commit flushes data changes to disk. If you would like to improve the performance, it is recommended to set DoFlushBuffers parameter to false, allowing OS to perform lazy writes on disk.
<br>

<br>
<b>ROLLBACK</b>
<br>
If an error occurs in a transaction, or if the user decides to cancel the transaction, then roll the transaction back. A ROLLBACK statement backs out all modifications made in the transaction by returning the data to the state it was in at the start of the transaction. A ROLLBACK also frees resources held by the transaction.
<br>
You can roll back transaction through either an </span><span style="font-family:Times New Roman; font-size:12pt; color:#000000">TABSDatabase.<a href=tabsdatabase_rollback.htm>Rollback</a> call</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"> or the ROLLBACK statement of Absolute Database SQL. It is also recommended to resresh open tables to avoid displaying data which is rolled back now, but make sure that there are no pending inserts or edits on these tables.
<br>

<br>

<br>
<b>Transaction Locks</b>
<br>

<br>
Absolute Database engine acquires table and record locks during the transaction. Unlike the usual locks, transaction locks remain unchanged after table modification until the end of transaction. These table locks don't prevent other users from reading locked table records, increasing concurrency level. 
<br>

<br>

<br>
<b>Deadlocking
<br>

<br>
</b>A deadlock occurs when there is a cyclic dependency between two or more threads for some set of resources.
<br>
Although deadlocks cannot be avoided completely, the number of deadlocks can be minimized. 
<br>

<br>
Minimizing deadlocks can increase transaction throughput and reduce system overhead because fewer transactions are: 
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><font face="Symbol" size="2" color="#000000">&#183;</font></span></span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Rolled back, undoing all the work performed by the transaction.
&nbsp;<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><font face="Symbol" size="2" color="#000000">&#183;</font></span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Resubmitted by applications because they were rolled back when deadlocked. 
&nbsp;<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"></span></td><td></td></tr></table><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
To help minimize deadlocks: 
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><font face="Symbol" size="2" color="#000000">&#183;</font></span></span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Access objects in the same order.
&nbsp;<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><font face="Symbol" size="2" color="#000000">&#183;</font></span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Avoid user interaction in transactions.
&nbsp;<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><font face="Symbol" size="2" color="#000000">&#183;</font></span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Keep transactions short and in one batch.
&nbsp;<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"></span></td><td></td></tr></table><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>

<br>
<b>SQL in Transactions</b>
<br>

<br>
INSERT, UPDATE and DELETE SQL statements implicitly use an internal kind of transaction if one is not already active.
<br>
SELECT peforms share locks on all processed tables, but this lock is freed as soon as SELECT satement is executed.
<br>

<br>

<br>
<b>Operations Not Allowed in Transactions
<br>
</b>
<br>
It is not permitted in transactions to perfrom:
<br>

<br>
   Create table (CreateTable method, SQL CREATE TABLE)
<br>
   Delete table (DeleteTable method, SQL DROP TABLE)
<br>
   Empty table (EmptyTable method)
<br>
   Copy table (CopyTable method)
<br>
   Rename table (RenameTable method, SQL ALTER TABLE)
<br>
   Restructure table (RestructureTable method, SQL ALTER TABLE)
<br>
   RenameField in a table (RenameField method, SQL ALTER TABLE)
<br>
   Add index to table (AddIndex method, SQL CREATE INDEX)
<br>
   Delete index from table (DeleteIndex, DeleteAllIndexes methods, SQL DROP INDEX)
<br>

<br>

<br>
<b>Isolation Level
<br>
</b>
<br>
Transaction isolation level determines how a transaction interacts with other simultaneous transactions when they work with the same tables, and how much a transaction sees of the work performed by other transactions.
<br>
Absolute Database supports ReadCommited level.
<br>
ReadCommitted<b> </b>permits reading of committed (permanent) changes made to the database by other simultaneous transactions. 
<br>

<br>

<br>
<b>Data Integrity
<br>
</b>
<br>
Absolute Database buffers in memory all changes made by transaction until commit or rollback.
<br>
If trransaction is commited, then all changes are written by the short operation. This allows to keep a good level of data integrity even in case of unexpected power loss or network problems.
<br>
If however the process of writing changes was interrupted, for example in such cases when very large trahsactions are performed and commiting process was legthy, the Absolute Database engine will detect if writing changes was interrupted and will suggest an auto-repair of a database file.
<br>

<br>

<br>
</span></span>

<!--#include virtual="/inc/footer.php"--> 
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -