v5:userguide:transactions
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
userguide:transactions [2015/12/29 20:49] – mnewnham | v5:userguide:transactions [2020/08/26 10:09] (current) – [Usage] Add braces as suggested by @peterdd in #629 dregad | ||
---|---|---|---|
Line 1: | Line 1: | ||
======Transaction Handling In ADOdb ====== | ======Transaction Handling In ADOdb ====== | ||
===== Overview ===== | ===== Overview ===== | ||
- | There are 2 ways of overriding the default transaction handling in ADOdb, **Granular** and **Smart**. Each way holds benefits but they cannot be mixed. Each method comprises a series of methods. | + | There are 2 ways of overriding the default |
* Granular transactions allow full control of individual commits | * Granular transactions allow full control of individual commits | ||
Line 11: | Line 11: | ||
<WRAP right info 300px> | <WRAP right info 300px> | ||
MySQL myIsam tables are always granular, and ignore any transaction control methods coded. You cannot rollback or fail an update into that table type. Use InnoDB table types instead. | MySQL myIsam tables are always granular, and ignore any transaction control methods coded. You cannot rollback or fail an update into that table type. Use InnoDB table types instead. | ||
+ | |||
+ | This also applies to any sequences that might have been updated in the transaction, | ||
</ | </ | ||
If ADOdb transaction handling is not used, then the transaction handling method is controlled by whatever is set by the database. Possible methods are: | If ADOdb transaction handling is not used, then the transaction handling method is controlled by whatever is set by the database. Possible methods are: | ||
Line 23: | Line 25: | ||
<WRAP right box> | <WRAP right box> | ||
== Available Methods == | == Available Methods == | ||
- | [[reference: | + | [[v5:reference:connection: |
- | [[reference: | + | [[v5:reference:connection: |
- | [[reference: | + | [[v5:reference:connection: |
+ | == See Also == | ||
+ | [[v5: | ||
+ | [[v5: | ||
</ | </ | ||
When using granular transactions, | When using granular transactions, | ||
Line 41: | Line 46: | ||
$ok = $conn-> | $ok = $conn-> | ||
- | if ($ok) | + | if ($ok) { |
/* | /* | ||
* The previous execution succeeded, do some more | * The previous execution succeeded, do some more | ||
| | ||
$ok = $conn-> | $ok = $conn-> | ||
- | else | + | } else { |
/* | /* | ||
* Branch, do some other work, then return | * Branch, do some other work, then return | ||
*/ | */ | ||
- | if (!$ok) | + | } |
+ | |||
+ | if (!$ok) | ||
/* | /* | ||
* Test the last insertion, if not successful roll | * Test the last insertion, if not successful roll | ||
Line 56: | Line 63: | ||
*/ | */ | ||
$conn-> | $conn-> | ||
- | else | + | } else { |
/* | /* | ||
* Go ahead and commit | * Go ahead and commit | ||
*/ | */ | ||
$conn-> | $conn-> | ||
+ | } | ||
</ | </ | ||
----------------------------- | ----------------------------- | ||
Line 66: | Line 74: | ||
<WRAP right box> | <WRAP right box> | ||
== Available Methods == | == Available Methods == | ||
- | [[reference: | + | [[v5:reference:connection: |
- | [[reference: | + | [[v5:reference:connection: |
- | [[reference: | + | [[v5:reference:connection: |
- | [[reference: | + | [[v5:reference:connection: |
+ | == See Also == | ||
+ | [[v5: | ||
+ | [[v5: | ||
</ | </ | ||
- | Smart Transactions are much easier to use in large procedures because you do not have to track the error status. You start a smart transaction by calling | + | Smart Transactions are much easier to use in large procedures because you do not have to track the error status. You start a smart transaction by calling |
<code php> | <code php> | ||
Line 82: | Line 93: | ||
* Execute some SQL | * Execute some SQL | ||
*/ | */ | ||
- | $conn->Execute($sql); | + | $conn->execute($sql); |
/* | /* | ||
* Execute some more SQL | * Execute some more SQL | ||
*/ | */ | ||
- | $conn->Execute($Sql2); | + | $conn->execute($sql2); |
/* | /* | ||
Line 96: | Line 107: | ||
</ | </ | ||
- | CompleteTrans() detects when an SQL error occurs, and will Rollback/Commit as appropriate. | + | [[v5: |
- | You can force a rollback even if no error occured, using failTrans(). Note that the rollback is done in CompleteTrans(). | + | You can force a rollback even if no transactional |
<code php> | <code php> | ||
Line 105: | Line 116: | ||
$conn-> | $conn-> | ||
- | if (!CheckRecords()) | + | if (!checkRecords()) |
$conn-> | $conn-> | ||
- | $conn->Execute($Sql2); | + | /* |
+ | * Even though failTrans was issued before this statement, | ||
+ | * it will also be rolled back | ||
+ | */ | ||
+ | $conn->execute($sql2); | ||
- | $conn->CompleteTrans(); | + | $conn->completeTrans(); |
</ | </ | ||
- | You can also check if a transaction has failed, using HasFailedTrans(), which returns true if FailTrans() was called, | + | You can also check if a transaction has failed, using [[v5: |
+ | * if [[v5: | ||
+ | * There was an error in the SQL execution. | ||
+ | |||
+ | Make sure you call '' | ||
Line 132: | Line 151: | ||
*/ | */ | ||
$conn-> | $conn-> | ||
- | if (!CheckRecords()) | + | if (!checkRecords()) |
/* | /* | ||
* This is applied to the outer block | * This is applied to the outer block | ||
Line 151: | Line 170: | ||
==== Savepoints ==== | ==== Savepoints ==== | ||
Savepoints are currently not supported. | Savepoints are currently not supported. | ||
- |
v5/userguide/transactions.txt · Last modified: 2020/08/26 10:09 by dregad