[Simple related questions] simulate Oracle sequence locks
Source: Internet
Author: User
[Simple question] simulate Oracle sequence locks. I will learn more about the locking mechanism in the future, because I am eager to use it. MYSQL simulates the order of ORACLE. CREATETABLE 'pb _ sequence '(& nbsp; 'sequence _ id' int (11) NOTNULLDEFA [simple question] simulate the Oracle sequence lock problem.
I will learn more about the locking mechanism in the future, because I am eager to use it.
MYSQL simulates the order of ORACLE.
Create table 'pb _ sequence '(
'Sequence _ id' int (11) not null default '0 ',
'Sequence _ name' varchar (25) default null,
'Sequence _ value' bigint (20) default null,
'Sequence _ type' varchar (20) default null,
Primary key ('sequence _ id ')
) ENGINE = InnoDB default charset = utf8;
Sequence_name: Sequence Name
Sequence_value: ordinal value
I'm getting select sequence_value from pb_sequence where sequence_name = 'MySQL _ sequence'
We all know that this record will be locked when I query it. No one can query this record. Otherwise, the data is inconsistent.
Then update pb_sequence set sequence_value = sequence_value + 1 where sequence_name = 'MySQL _ sequence'
The lock can be released only after I update it.
-----------------------
Can I use PDO to write this sentence? Is this related to PDO? Or is it only related to SQL statements? Because I see that PDO only enables transactions.
There seems to be no setting for PDO to block other users when you query it?
------ Solution --------------------
SELECT... FOR UPDATE
Http://dev.mysql.com/doc/refman/5.0/en/innodb-locking-reads.html
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service