docs: add FOR UPDATE clause to MySQL transaction example #4035
+6
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3485
Summary
Adds the
FOR UPDATE
clause to the MySQL transaction example to prevent race conditions when reading and then updating data within the same transaction.Changes Made
Modified GetRecord query to include
FOR UPDATE
clause:Added explanatory section about locking reads in transactions to help users understand when and why to use
SELECT ... FOR UPDATE
Problem Addressed
The current transaction example shows a read-then-update pattern without proper row locking, which can lead to race conditions in MySQL where other transactions might modify the same rows between the SELECT and UPDATE operations.
According to the MySQL documentation:
Solution
The
FOR UPDATE
clause provides exclusive row locking in MySQL/InnoDB, preventing other transactions from modifying the selected rows until the current transaction completes.References
🤖 Generated with Claude Code